code: function encodeObject( encoder, object ) {
  
  	// Check ByRef internally
  	var id = encoder.lookupIRef( object );
  	if (id > -1) { encodeIREF( encoder, id ); return; }
  
  	// Check ByRef externally
  	id = encoder.lookupXRef( object );
  	if (id > -1) { encodeXREF( encoder, id); return }
  
  	// Lookup object type
  	var enc = encoder.profile.encode(object);
  	if (!enc) {
  		throw new Errors.XRefError('An object trying to encode was not declared in the object table!');
  	}
  
  	// Populate property table
  	var eid = enc[0], propertyTable = enc[1]( object );
  
  	// Check ByVal ref
  	id = encoder.lookupIVal( propertyTable, eid );
  	if (id > -1) 
  		{ encodeIREF( encoder, id ); return; }
  
  	// Keep this object for internal cross-refferencing
  	encoder.log(LOG.OBJ,"eid="+eid+", properties="+propertyTable.length);
  	encoder.keepIRef( object, propertyTable, eid );
  
  	// Check if we should use 12-bit or 5-bit index
  	if (eid < 32) {
  
  		// Write entity opcode
  		encoder.stream8.write( pack1b( PRIM_OP.OBJECT | OBJ_OP.KNOWN_5 | eid ) );
  		encoder.counters.op_prm+=1;
  
  	} else {
  
  		// Split 12-bit number
  		var eid_hi = (eid & 0xF00) >> 8,
  			eid_lo = eid & 0xFF;
  
  		// Write entity
  		encoder.stream8.write( pack1b( PRIM_OP.OBJECT | OBJ_OP.KNOWN_12 | eid_hi ) );
  		encoder.stream8.write( pack1b( eid_lo ) );
  		encoder.counters.op_prm+=2;
  
  	}
  
  	// Write property table as an array
  	encodeArray( encoder, propertyTable );
  
  }
docs: Encode a javascript object