encoder.js
function( object ) {
		var keys = Object.keys(object), k, v, lookupString,
			lVals = [], lArrays = [], lObjects = [];

		// Sort to values, arrays and objects
		lookupString = "";
		for (var i=0; i<keys.length; ++i) {
			k = keys[i]; v = object[k];
			if ((v instanceof Uint8Array) || (v instanceof Int8Array) ||
				(v instanceof Uint16Array) || (v instanceof Int16Array) ||
				(v instanceof Uint32Array) || (v instanceof Int32Array) ||
				(v instanceof Float32Array) || (v instanceof Float64Array) ||
				(v instanceof Array) ) {
				lArrays.push(k);
				lookupString += "@"+k;
			} else if (v.constructor === ({}).constructor) {
				lObjects.push(k);
				lookupString += "%"+k;
			} else {
				lVals.push(k);
				lookupString += "$"+k;
			}
		}

		// Lookup or create signature
		i = this.plainObjectSignatureLookup[lookupString];
		if (i === undefined) {

			// Compile signature
			var sigbuf = [];
			sigbuf.push( pack2b( lVals.length ) );
			for (var i=0; i<lVals.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lVals[i]) ) );
			}
			sigbuf.push( pack2b( lArrays.length ) );
			for (var i=0; i<lArrays.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lArrays[i]) ) );
			}
			sigbuf.push( pack2b( lObjects.length ) );
			for (var i=0; i<lObjects.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lObjects[i]) ) );
			}

			// Encode to the 16-bit stream
			this.plainObjectSignatureTable.push( Buffer.concat( sigbuf ) );
			this.plainObjectSignatureLookup[lookupString] 
				= i = this.plainObjectSignatureTable.length - 1;
		}

		// Return index
		return [i, lVals, lArrays, lObjects];
	}
function( object ) {
		var keys = Object.keys(object), k, v, lookupString,
			lVals = [], lArrays = [], lObjects = [];

		// Sort to values, arrays and objects
		lookupString = "";
		for (var i=0; i<keys.length; ++i) {
			k = keys[i]; v = object[k];
			if ((v instanceof Uint8Array) || (v instanceof Int8Array) ||
				(v instanceof Uint16Array) || (v instanceof Int16Array) ||
				(v instanceof Uint32Array) || (v instanceof Int32Array) ||
				(v instanceof Float32Array) || (v instanceof Float64Array) ||
				(v instanceof Array) ) {
				lArrays.push(k);
				lookupString += "@"+k;
			} else if (v.constructor === ({}).constructor) {
				lObjects.push(k);
				lookupString += "%"+k;
			} else {
				lVals.push(k);
				lookupString += "$"+k;
			}
		}

		// Lookup or create signature
		i = this.plainObjectSignatureLookup[lookupString];
		if (i === undefined) {

			// Compile signature
			var sigbuf = [];
			sigbuf.push( pack2b( lVals.length ) );
			for (var i=0; i<lVals.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lVals[i]) ) );
			}
			sigbuf.push( pack2b( lArrays.length ) );
			for (var i=0; i<lArrays.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lArrays[i]) ) );
			}
			sigbuf.push( pack2b( lObjects.length ) );
			for (var i=0; i<lObjects.length; ++i) {
				sigbuf.push( pack2b( this.stringID(lObjects[i]) ) );
			}

			// Encode to the 16-bit stream
			this.plainObjectSignatureTable.push( Buffer.concat( sigbuf ) );
			this.plainObjectSignatureLookup[lookupString] 
				= i = this.plainObjectSignatureTable.length - 1;
		}

		// Return index
		return [i, lVals, lArrays, lObjects];
	}
function ( object ) { var keys = Object . keys ( object ) , k , v , lookupString , lVals = [ ] , lArrays = [ ] , lObjects = [ ] ; // Sort to values, arrays and objects lookupString = "" ; for ( var i = 0 ; i < keys . length ; ++ i ) { k = keys [ i ] ; v = object [ k ] ; if ( ( v instanceof Uint8Array ) || ( v instanceof Int8Array ) || ( v instanceof Uint16Array ) || ( v instanceof Int16Array ) || ( v instanceof Uint32Array ) || ( v instanceof Int32Array ) || ( v instanceof Float32Array ) || ( v instanceof Float64Array ) || ( v instanceof Array ) ) { lArrays . push ( k ) ; lookupString += "@" + k ; } else if ( v . constructor === ( { } ) . constructor ) { lObjects . push ( k ) ; lookupString += "%" + k ; } else { lVals . push ( k ) ; lookupString += "$" + k ; } } // Lookup or create signature i = this . plainObjectSignatureLookup [ lookupString ] ; if ( i === undefined ) { // Compile signature var sigbuf = [ ] ; sigbuf . push ( pack2b ( lVals . length ) ) ; for ( var i = 0 ; i < lVals . length ; ++ i ) { sigbuf . push ( pack2b ( this . stringID ( lVals [ i ] ) ) ) ; } sigbuf . push ( pack2b ( lArrays . length ) ) ; for ( var i = 0 ; i < lArrays . length ; ++ i ) { sigbuf . push ( pack2b ( this . stringID ( lArrays [ i ] ) ) ) ; } sigbuf . push ( pack2b ( lObjects . length ) ) ; for ( var i = 0 ; i < lObjects . length ; ++ i ) { sigbuf . push ( pack2b ( this . stringID ( lObjects [ i ] ) ) ) ; } // Encode to the 16-bit stream this . plainObjectSignatureTable . push ( Buffer . concat ( sigbuf ) ) ; this . plainObjectSignatureLookup [ lookupString ] = i = this . plainObjectSignatureTable . length - 1 ; } // Return index return [ i , lVals , lArrays , lObjects ] ; }
Get object signature
Get object signature