decoder.js
function decodeObject( bundle, database, op ) {
	if ( !(op & 0x20) || ((op & 0x30) === 0x20) ) { // Predefined objects
		var eid = op;
		if (op & 0x20) eid = bundle.u8[bundle.i8++] | ((op & 0x0F) << 8);

		// Fetch object class
		var FACTORY = bundle.profile.decode(eid);
		if (FACTORY === undefined) {
			throw new Errors.AssertError('Could not found known object entity #'+eid+'!');
		}

		// Call entity factory
		var instance = FACTORY.create();
		// Keep on irefs
		bundle.iref_table.push( instance );
		// Fetch property table
		// console.assert(eid != 50);
		var prop_table = decodePrimitive( bundle, database );

		// Run initializer
		FACTORY.init( instance, prop_table, 1, 0 );

		// Append debug metadata
		DEBUG && __debugMeta( instance, 'object.known', { 'eid': eid } );
		return instance;

	} else if ((op & 0x3C) === 0x38) { // Primitive object
		var poid = (op & 0x03);
		switch (poid) {
			case 0:
				var date = bundle.f64[bundle.i64++];
				var tzOffset = bundle.s8[bundle.i8++] * 10;

				// Return date
				return DEBUG 
						? __debugMeta( new Date( date ), 'object.date', {} )
						: new Date( date );

			default:
				throw new Errors.AssertError('Unknown primitive object with POID #'+poid+'!');
		}

	} else if ((op & 0x38) === 0x30) { // Simple object with known signature
		// Get values
		var eid = ((op & 0x07) << 8) | bundle.u8[bundle.i8++],
			values = decodePrimitive( bundle, database ),
			factory = bundle.factory_plain[eid];

		// Check for invalid objects
		if (factory === undefined)
			throw new Errors.AssertError('Could not found simple object signature with id #'+eid+'!');

		// Create object
		return DEBUG
			? __debugMeta( factory(values), 'object.plain', { 'eid': eid } )
			: factory(values);

	} else {
		throw new Errors.AssertError('Unexpected object opcode 0x'+op.toString(16)+'!');
	}

}
function decodeObject( bundle, database, op ) {
	if ( !(op & 0x20) || ((op & 0x30) === 0x20) ) { // Predefined objects
		var eid = op;
		if (op & 0x20) eid = bundle.u8[bundle.i8++] | ((op & 0x0F) << 8);

		// Fetch object class
		var FACTORY = bundle.profile.decode(eid);
		if (FACTORY === undefined) {
			throw new Errors.AssertError('Could not found known object entity #'+eid+'!');
		}

		// Call entity factory
		var instance = FACTORY.create();
		// Keep on irefs
		bundle.iref_table.push( instance );
		// Fetch property table
		// console.assert(eid != 50);
		var prop_table = decodePrimitive( bundle, database );

		// Run initializer
		FACTORY.init( instance, prop_table, 1, 0 );

		// Append debug metadata
		DEBUG && __debugMeta( instance, 'object.known', { 'eid': eid } );
		return instance;

	} else if ((op & 0x3C) === 0x38) { // Primitive object
		var poid = (op & 0x03);
		switch (poid) {
			case 0:
				var date = bundle.f64[bundle.i64++];
				var tzOffset = bundle.s8[bundle.i8++] * 10;

				// Return date
				return DEBUG 
						? __debugMeta( new Date( date ), 'object.date', {} )
						: new Date( date );

			default:
				throw new Errors.AssertError('Unknown primitive object with POID #'+poid+'!');
		}

	} else if ((op & 0x38) === 0x30) { // Simple object with known signature
		// Get values
		var eid = ((op & 0x07) << 8) | bundle.u8[bundle.i8++],
			values = decodePrimitive( bundle, database ),
			factory = bundle.factory_plain[eid];

		// Check for invalid objects
		if (factory === undefined)
			throw new Errors.AssertError('Could not found simple object signature with id #'+eid+'!');

		// Create object
		return DEBUG
			? __debugMeta( factory(values), 'object.plain', { 'eid': eid } )
			: factory(values);

	} else {
		throw new Errors.AssertError('Unexpected object opcode 0x'+op.toString(16)+'!');
	}

}
function decodeObject ( bundle , database , op ) { if ( ! ( op & 0x20 ) || ( ( op & 0x30 ) === 0x20 ) ) { // Predefined objects var eid = op ; if ( op & 0x20 ) eid = bundle . u8 [ bundle . i8 ++ ] | ( ( op & 0x0F ) << 8 ) ; // Fetch object class var FACTORY = bundle . profile . decode ( eid ) ; if ( FACTORY === undefined ) { throw new Errors . AssertError ( 'Could not found known object entity #' + eid + '!' ) ; } // Call entity factory var instance = FACTORY . create ( ) ; // Keep on irefs bundle . iref_table . push ( instance ) ; // Fetch property table // console.assert(eid != 50); var prop_table = decodePrimitive ( bundle , database ) ; // Run initializer FACTORY . init ( instance , prop_table , 1 , 0 ) ; // Append debug metadata DEBUG && __debugMeta ( instance , 'object.known' , { 'eid' : eid } ) ; return instance ; } else if ( ( op & 0x3C ) === 0x38 ) { // Primitive object var poid = ( op & 0x03 ) ; switch ( poid ) { case 0 : var date = bundle . f64 [ bundle . i64 ++ ] ; var tzOffset = bundle . s8 [ bundle . i8 ++ ] * 10 ; // Return date return DEBUG ? __debugMeta ( new Date ( date ) , 'object.date' , { } ) : new Date ( date ) ; default : throw new Errors . AssertError ( 'Unknown primitive object with POID #' + poid + '!' ) ; } } else if ( ( op & 0x38 ) === 0x30 ) { // Simple object with known signature // Get values var eid = ( ( op & 0x07 ) << 8 ) | bundle . u8 [ bundle . i8 ++ ] , values = decodePrimitive ( bundle , database ) , factory = bundle . factory_plain [ eid ] ; // Check for invalid objects if ( factory === undefined ) throw new Errors . AssertError ( 'Could not found simple object signature with id #' + eid + '!' ) ; // Create object return DEBUG ? __debugMeta ( factory ( values ) , 'object.plain' , { 'eid' : eid } ) : factory ( values ) ; } else { throw new Errors . AssertError ( 'Unexpected object opcode 0x' + op . toString ( 16 ) + '!' ) ; } }
Read an object from the bundle
Read an object from the bundle