encoder.js
function encodeLIREF(encoder, op8, op16, local_ids, xrid) {
	var DEBUG_THIS = false;

	// Check if the given object is part of the array
	var id=-1, i=0, l=local_ids.length;
	for (;i<l;++i) {
		if (i > 65535) break;
		if (local_ids[i] === xrid) {
			id = i;
			break;
		}
	}

	if (id === -1) { // IREF
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.IREF | ((xrid >> 16) & 0xF), false ) );
		op16.push( pack2b( xrid & 0xFFFF, false ) );
		encoder.counters.op_iref+=3;
		local_ids.push(xrid);
		if (DEBUG_THIS) console.log("->- IREF(",xrid,",",id,")");
	} else if (id < 128) { // LREF_7
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_7 | (id & 0x7F), false ) );
		encoder.counters.op_iref+=1;
		if (DEBUG_THIS) console.log("->- LREF_7(",xrid,",",id,")");
	} else if (id < 2048) { // LREF_11
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_11 | ((id >> 8) & 0x7), false ) );
		op8.push( pack1b( id & 0xFF, false ) );
		encoder.counters.op_iref+=2;
		if (DEBUG_THIS) console.log("->- LREF_11(",xrid,",",id,")");
	} else if (id < 65536) { // LREF_16
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_16, false ) );
		op16.push( pack2b( id & 0xFFFF, false ) );
		encoder.counters.op_iref+=3;
		if (DEBUG_THIS) console.log("->- LREF_16(",xrid,",",id,")");
	}

}
function encodeLIREF(encoder, op8, op16, local_ids, xrid) {
	var DEBUG_THIS = false;

	// Check if the given object is part of the array
	var id=-1, i=0, l=local_ids.length;
	for (;i<l;++i) {
		if (i > 65535) break;
		if (local_ids[i] === xrid) {
			id = i;
			break;
		}
	}

	if (id === -1) { // IREF
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.IREF | ((xrid >> 16) & 0xF), false ) );
		op16.push( pack2b( xrid & 0xFFFF, false ) );
		encoder.counters.op_iref+=3;
		local_ids.push(xrid);
		if (DEBUG_THIS) console.log("->- IREF(",xrid,",",id,")");
	} else if (id < 128) { // LREF_7
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_7 | (id & 0x7F), false ) );
		encoder.counters.op_iref+=1;
		if (DEBUG_THIS) console.log("->- LREF_7(",xrid,",",id,")");
	} else if (id < 2048) { // LREF_11
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_11 | ((id >> 8) & 0x7), false ) );
		op8.push( pack1b( id & 0xFF, false ) );
		encoder.counters.op_iref+=2;
		if (DEBUG_THIS) console.log("->- LREF_11(",xrid,",",id,")");
	} else if (id < 65536) { // LREF_16
		op8.push( pack1b( PRIM_BULK_KNOWN_OP.LREF_16, false ) );
		op16.push( pack2b( id & 0xFFFF, false ) );
		encoder.counters.op_iref+=3;
		if (DEBUG_THIS) console.log("->- LREF_16(",xrid,",",id,")");
	}

}
function encodeLIREF ( encoder , op8 , op16 , local_ids , xrid ) { var DEBUG_THIS = false ; // Check if the given object is part of the array var id = - 1 , i = 0 , l = local_ids . length ; for ( ; i < l ; ++ i ) { if ( i > 65535 ) break ; if ( local_ids [ i ] === xrid ) { id = i ; break ; } } if ( id === - 1 ) { // IREF op8 . push ( pack1b ( PRIM_BULK_KNOWN_OP . IREF | ( ( xrid >> 16 ) & 0xF ) , false ) ) ; op16 . push ( pack2b ( xrid & 0xFFFF , false ) ) ; encoder . counters . op_iref += 3 ; local_ids . push ( xrid ) ; if ( DEBUG_THIS ) console . log ( "->- IREF(" , xrid , "," , id , ")" ) ; } else if ( id < 128 ) { // LREF_7 op8 . push ( pack1b ( PRIM_BULK_KNOWN_OP . LREF_7 | ( id & 0x7F ) , false ) ) ; encoder . counters . op_iref += 1 ; if ( DEBUG_THIS ) console . log ( "->- LREF_7(" , xrid , "," , id , ")" ) ; } else if ( id < 2048 ) { // LREF_11 op8 . push ( pack1b ( PRIM_BULK_KNOWN_OP . LREF_11 | ( ( id >> 8 ) & 0x7 ) , false ) ) ; op8 . push ( pack1b ( id & 0xFF , false ) ) ; encoder . counters . op_iref += 2 ; if ( DEBUG_THIS ) console . log ( "->- LREF_11(" , xrid , "," , id , ")" ) ; } else if ( id < 65536 ) { // LREF_16 op8 . push ( pack1b ( PRIM_BULK_KNOWN_OP . LREF_16 , false ) ) ; op16 . push ( pack2b ( id & 0xFFFF , false ) ) ; encoder . counters . op_iref += 3 ; if ( DEBUG_THIS ) console . log ( "->- LREF_16(" , xrid , "," , id , ")" ) ; } }
Helper function to encode local-lookup internal references
Helper function to encode local - lookup internal references