encoder.js
function encodeArray_Chunk( encoder, data, chunk ) {
	var n_type, na;

	// console.log(">>> CFWA Chunk="+_ARR_CHUNK[chunk[2]],", from=" + chunk[0] + ", len=" + chunk[1] + ", arr=" + data.length);
	// console.log(">>> =",data);

	// Encode array component according to chunk type
	switch (chunk[2]) {

		// Encode as an array of primitives
		case ARR_CHUNK.PRIMITIVES:
			if (data.length < 256) {
				encodeArray_PRIM_SHORT( encoder, data );
			} else {
				encodeArray_PRIM_RAW( encoder, data );
			}
			break;

		// Encode as a repeated array
		case ARR_CHUNK.REPEAT:

			// Prioritize numeric type suggested by chunk
			n_type = chunk[4];
			if (n_type === NUMTYPE.UNKNOWN)
				n_type = getTypedArrayType( data );

			// Check if the repeated items are numeric or primitivie
			if ( n_type <= NUMTYPE.NUMERIC ) {

				/* If that's numeric, perform fast numeric analysis to 
				   find it's type. */
				if (n_type === NUMTYPE.NUMERIC) {
					na = analyzeNumericArray( data, false );
					n_type = na.type;
				}

				// Encode numeric repeated array if number
				encodeArray_NUM_REPEATED( encoder, data, n_type );
			} else {
				// Encode primitive repeated array otherwise
				encodeArray_PRIM_REPEATED( encoder, data );
			}
			break;

		// encode as a numeric array
		case ARR_CHUNK.NUMERIC:
			encodeArray_Numeric( encoder, data, chunk[3] );
			break;

		// Encode as a bulk of plain objects
		case ARR_CHUNK.BULK_PLAIN:
			encodeArray_PRIM_BULK_PLAIN( encoder, data, chunk[3] );
			break;

		// Encode as a bulk of known objects
		case ARR_CHUNK.BULK_KNOWN:
			encodeArray_PRIM_BULK_KNOWN( encoder, data, chunk[3] );
			break;

		// Just precaution
		default:
			throw new Errors.EncodeError('Trying to encode an unknown chunk (type='+chunkType+')!');

	}
}
function encodeArray_Chunk( encoder, data, chunk ) {
	var n_type, na;

	// console.log(">>> CFWA Chunk="+_ARR_CHUNK[chunk[2]],", from=" + chunk[0] + ", len=" + chunk[1] + ", arr=" + data.length);
	// console.log(">>> =",data);

	// Encode array component according to chunk type
	switch (chunk[2]) {

		// Encode as an array of primitives
		case ARR_CHUNK.PRIMITIVES:
			if (data.length < 256) {
				encodeArray_PRIM_SHORT( encoder, data );
			} else {
				encodeArray_PRIM_RAW( encoder, data );
			}
			break;

		// Encode as a repeated array
		case ARR_CHUNK.REPEAT:

			// Prioritize numeric type suggested by chunk
			n_type = chunk[4];
			if (n_type === NUMTYPE.UNKNOWN)
				n_type = getTypedArrayType( data );

			// Check if the repeated items are numeric or primitivie
			if ( n_type <= NUMTYPE.NUMERIC ) {

				/* If that's numeric, perform fast numeric analysis to 
				   find it's type. */
				if (n_type === NUMTYPE.NUMERIC) {
					na = analyzeNumericArray( data, false );
					n_type = na.type;
				}

				// Encode numeric repeated array if number
				encodeArray_NUM_REPEATED( encoder, data, n_type );
			} else {
				// Encode primitive repeated array otherwise
				encodeArray_PRIM_REPEATED( encoder, data );
			}
			break;

		// encode as a numeric array
		case ARR_CHUNK.NUMERIC:
			encodeArray_Numeric( encoder, data, chunk[3] );
			break;

		// Encode as a bulk of plain objects
		case ARR_CHUNK.BULK_PLAIN:
			encodeArray_PRIM_BULK_PLAIN( encoder, data, chunk[3] );
			break;

		// Encode as a bulk of known objects
		case ARR_CHUNK.BULK_KNOWN:
			encodeArray_PRIM_BULK_KNOWN( encoder, data, chunk[3] );
			break;

		// Just precaution
		default:
			throw new Errors.EncodeError('Trying to encode an unknown chunk (type='+chunkType+')!');

	}
}
function encodeArray_Chunk ( encoder , data , chunk ) { var n_type , na ; // console.log(">>> CFWA Chunk="+_ARR_CHUNK[chunk[2]],", from=" + chunk[0] + ", len=" + chunk[1] + ", arr=" + data.length); // console.log(">>> =",data); // Encode array component according to chunk type switch ( chunk [ 2 ] ) { // Encode as an array of primitives case ARR_CHUNK . PRIMITIVES : if ( data . length < 256 ) { encodeArray_PRIM_SHORT ( encoder , data ) ; } else { encodeArray_PRIM_RAW ( encoder , data ) ; } break ; // Encode as a repeated array case ARR_CHUNK . REPEAT : // Prioritize numeric type suggested by chunk n_type = chunk [ 4 ] ; if ( n_type === NUMTYPE . UNKNOWN ) n_type = getTypedArrayType ( data ) ; // Check if the repeated items are numeric or primitivie if ( n_type <= NUMTYPE . NUMERIC ) { /* If that's numeric, perform fast numeric analysis to 
				   find it's type. */ if ( n_type === NUMTYPE . NUMERIC ) { na = analyzeNumericArray ( data , false ) ; n_type = na . type ; } // Encode numeric repeated array if number encodeArray_NUM_REPEATED ( encoder , data , n_type ) ; } else { // Encode primitive repeated array otherwise encodeArray_PRIM_REPEATED ( encoder , data ) ; } break ; // encode as a numeric array case ARR_CHUNK . NUMERIC : encodeArray_Numeric ( encoder , data , chunk [ 3 ] ) ; break ; // Encode as a bulk of plain objects case ARR_CHUNK . BULK_PLAIN : encodeArray_PRIM_BULK_PLAIN ( encoder , data , chunk [ 3 ] ) ; break ; // Encode as a bulk of known objects case ARR_CHUNK . BULK_KNOWN : encodeArray_PRIM_BULK_KNOWN ( encoder , data , chunk [ 3 ] ) ; break ; // Just precaution default : throw new Errors . EncodeError ( 'Trying to encode an unknown chunk (type=' + chunkType + ')!' ) ; } }
Encode an array chunk, previously constructed
by chunkForwardanalysis
Encode an array chunk previously constructed by chunkForwardanalysis