Script object dynamic layout feature demonstration.
When executed in ES script console tool, it outputs the following:
test0 object size = 3
test1 object size = 3
test1 object properties = type;attributeNames;propertyNames;persistentPropertyNames;weakReference;size;offset;classAttributeNames;fieldNames;buffer;tag;u8
test1 object fields = f_u8;f_u16
test1 object size = 15
test1 object properties = type;attributeNames;propertyNames;persistentPropertyNames;weakReference;size;offset;classAttributeNames;fieldNames;buffer;tag;u8;dt;float
test1 object fields = f_u8;f_u16;f_dt;f_float
// ES script dynamic data object layout
//
object DLobject
{
// Object variable(s)
// Do not influence the object size
var m_tag;
// Object data fields, these form the object data buffer, and
// its size. Supported are signed and unsigned ints, 8-64 bit wide
// 32 bit floats, 64 bit date time, and arrays.
//
esU8 f_u8;
esU16 f_u16;
if( !m_tag#isEmpty() && m_tag > 128 )
{
esDT f_dt;
esF f_float;
function addFloat(f)
{
f_float += f;
}
property dt;
read: { return f_dt; }
write: { f_dt = __value; }
property float;
read: { return f_float#asDouble(); }
}
// Object CTOR
new( tag )
{
m_tag = tag;
}
property tag;
write: { m_tag = __value; }
property u8;
read: { return f_u8; }
}
var test0 = new DLobject(null), test1 = new DLobject(11);
EsScriptDebug::log( "test0 object size = %d", test0$size );
EsScriptDebug::log( "test1 object size = %d", test1$size );
EsScriptDebug::log( "test1 object properties = %s", test1$propertyNames );
EsScriptDebug::log( "test1 object fields = %s", test1$fieldNames );
// Assign the new tag value, the object test1 changes its layout dynamically
test1$tag = 400; // Or test1.m_tag = 400;
EsScriptDebug::log( "test1 object size = %d", test1$size );
EsScriptDebug::log( "test1 object properties = %s", test1$propertyNames );
EsScriptDebug::log( "test1 object fields = %s", test1$fieldNames );