encoder.js
function encodeArray_PRIM_CHUNK( encoder, data, chunks ) {

	//
	// Chunked Primitive Array (PRIM_CHUNK)
	//
	// ........
	// 01111101
	//

	var chunk, chunkType, chunkSize, chunkSubType, part, num_flag = 0x2;

	// Check if all chunks are numeric
	if (!chunks.is_numeric) num_flag = 0;

	// Write chunk header
	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK | NUMTYPE_LN.UINT16 | num_flag ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK | NUMTYPE_LN.UINT32 | num_flag ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Log
	encoder.counters.arr_prim_chunk+=1;
	encoder.log(LOG.ARR, "array.prim.chunk, len="+data.length+
		", chunks="+chunks.length+", peek="+data[0]+" [");
	encoder.logIndent(1);

	// Encode individual chunks
	for (var i=0, ofs=0, llen=chunks.length; i<llen; ++i) {
		encodeArray_Chunk( encoder, data.slice(ofs, ofs+chunks[i][1]), chunks[i] );
		ofs += chunks[i][1];
	}

	// Write chunk termination
	// encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK_END ) );
	// encoder.counters.arr_hdr+=1;

	encoder.logIndent(-1);
	encoder.log(LOG.ARR, "]");

}
function encodeArray_PRIM_CHUNK( encoder, data, chunks ) {

	//
	// Chunked Primitive Array (PRIM_CHUNK)
	//
	// ........
	// 01111101
	//

	var chunk, chunkType, chunkSize, chunkSubType, part, num_flag = 0x2;

	// Check if all chunks are numeric
	if (!chunks.is_numeric) num_flag = 0;

	// Write chunk header
	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK | NUMTYPE_LN.UINT16 | num_flag ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK | NUMTYPE_LN.UINT32 | num_flag ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Log
	encoder.counters.arr_prim_chunk+=1;
	encoder.log(LOG.ARR, "array.prim.chunk, len="+data.length+
		", chunks="+chunks.length+", peek="+data[0]+" [");
	encoder.logIndent(1);

	// Encode individual chunks
	for (var i=0, ofs=0, llen=chunks.length; i<llen; ++i) {
		encodeArray_Chunk( encoder, data.slice(ofs, ofs+chunks[i][1]), chunks[i] );
		ofs += chunks[i][1];
	}

	// Write chunk termination
	// encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK_END ) );
	// encoder.counters.arr_hdr+=1;

	encoder.logIndent(-1);
	encoder.log(LOG.ARR, "]");

}
function encodeArray_PRIM_CHUNK ( encoder , data , chunks ) { // // Chunked Primitive Array (PRIM_CHUNK) // // ........ // 01111101 // var chunk , chunkType , chunkSize , chunkSubType , part , num_flag = 0x2 ; // Check if all chunks are numeric if ( ! chunks . is_numeric ) num_flag = 0 ; // Write chunk header if ( data . length < UINT16_MAX ) { // 16-bit length prefix encoder . stream8 . write ( pack1b ( ARR_OP . PRIM_CHUNK | NUMTYPE_LN . UINT16 | num_flag ) ) ; encoder . stream16 . write ( pack2b ( data . length , false ) ) ; encoder . counters . arr_hdr += 3 ; } else { // 32-bit length prefix encoder . stream8 . write ( pack1b ( ARR_OP . PRIM_CHUNK | NUMTYPE_LN . UINT32 | num_flag ) ) ; encoder . stream32 . write ( pack4b ( data . length , false ) ) ; encoder . counters . arr_hdr += 5 ; } // Log encoder . counters . arr_prim_chunk += 1 ; encoder . log ( LOG . ARR , "array.prim.chunk, len=" + data . length + ", chunks=" + chunks . length + ", peek=" + data [ 0 ] + " [" ) ; encoder . logIndent ( 1 ) ; // Encode individual chunks for ( var i = 0 , ofs = 0 , llen = chunks . length ; i < llen ; ++ i ) { encodeArray_Chunk ( encoder , data . slice ( ofs , ofs + chunks [ i ] [ 1 ] ) , chunks [ i ] ) ; ofs += chunks [ i ] [ 1 ] ; } // Write chunk termination // encoder.stream8.write( pack1b( ARR_OP.PRIM_CHUNK_END ) ); // encoder.counters.arr_hdr+=1; encoder . logIndent ( - 1 ) ; encoder . log ( LOG . ARR , "]" ) ; }
Encode array data as one or more chunks of other types
Encode array data as one or more chunks of other types