How to use @ably/msgpack-js - 2 common examples

To help you get started, we’ve selected a few @ably/msgpack-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ably / ably-js / tools / crypto / generate-test-data.js View on Github external
verboseOutput(util.inspect(encoded_message));
	verboseOutput('\n');

	/* JSON-encoded representation if not encrypted */
	var encoded_json = copy(encoded_message);
	if(isBuffer) {
		encoded_json.data = data.toString('base64');
		encoded_json.encoding = (encoding ? (encoding + '/') : '') + 'base64';
	}
	verboseOutput('Unencrypted JSON message format:');
	verboseOutput(JSON.stringify(encoded_json));
	verboseOutput('\n');

	/* unencrypted format msgpack */
	verboseOutput('Unencrypted msgpack message format:');
	hexdump(msgpack.encode(encoded_message));
	verboseOutput('\n');

	/* plaintext without padding */
	verboseOutput('Plaintext before encryption (without padding):');
	var plaintext = data;
	if(isString) {
		plaintext = new Buffer(plaintext);
		encoding = (encoding ? (encoding + '/') : '') + 'utf-8';
	}
	hexdump(plaintext);
	verboseOutput('\n');

	/* plaintext including padding */
	verboseOutput('Plaintext before encryption (including padding):');
	var paddedPlaintext = padPlaintext(plaintext);
	hexdump(paddedPlaintext);
github ably / ably-js / tools / crypto / generate-test-data.js View on Github external
};
	verboseOutput('Encrypted message format:');
	verboseOutput(util.inspect(encrypted_message));
	verboseOutput('\n');

	/* encrypted format (JSON) */
	var encrypted_json = copy(encrypted_message);
	encrypted_json.data = encrypted_message.data.toString('base64');
	encrypted_json.encoding = encrypted_message.encoding + '/base64'
	verboseOutput('Encrypted JSON message format:');
	verboseOutput(JSON.stringify(encrypted_json));
	verboseOutput('\n');

	/* encrypted format (msgpack)*/
	verboseOutput('Encrypted msgpack message format:');
	hexdump(msgpack.encode(encrypted_message));
	verboseOutput('\n');

	return {
		encoded: encoded_json,
		encrypted: encrypted_json
	};
}

@ably/msgpack-js

msgpack encoder and decoder in pure javascript based on creationix/msgpack-js updated to match the new v5 specification with string support.

Apache-2.0
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular @ably/msgpack-js functions