3 Value Encoding

The hla.omt module provides

First, import the module functions

import hla.omt as fom

Each encoding object provides the pack, unpack methods, and the octetBoundary property.

class HLAbasic( )
pack( value)
Returns encoded value.
encodedValue = fom.HLAfloat64LE.pack(3.14)
encodedValue += fom.HLAinteger16BE.pack(42)
unpack( value)
Returns a (value, offset) tuple. The offset indicates number of consumed bytes, i.e. offset of the next unpack operation.
value1, offset2 = fom.HLAfloat64LE.unpack(encodedValue)
value2, offset3 = fom.HLAinteger16BE.unpack(encodedValue[offset2:])
print value1, value2
octetBoundary
Read-only property. The octet boundary (in bytes) of this data type.

The hla.omt module defines the following basic types.

type name bytes endian
HLAoctet 1
HLAinteger16BE 2 Big
HLAinteger32BE 4 Big
HLAinteger64BE 8 Big
HLAfloat32BE 4 Big
HLAfloat64BE 8 Big
HLAinteger16LE 2 Little
HLAinteger32LE 4 Little
HLAinteger64LE 8 Little
HLAfloat32LE 4 Little
HLAfloat64LE 8 Little

Additional data types can be defined using the HLAencoding, HLAfixedArray, HLAvariableArray, or HLAfixedRecord class, or imported from an OMT DIF file.

HLAuse( filename)
Imports data types from an OMT DIF file. Format of the OMT DIF file is defined in IEEE 1516.2.

All the RPR-FOM classes and data types will become accessible from the module's dictionary.

fom.HLAuse('rpr2-d18.xml')

encodedValue = fom.WorldLocationStruct.pack({'X':0, 'Y':3.12, 'Z':1})
value, offset = fom.WorldLocationStruct.unpack(encodedValue)

class HLAencoding( typename)
Facilitates a forward type declaration. The typename is resolved from the module's dictionary once the pack or unpack method is called.

newType = fom.HLAencoding('WorldLocationStruct')
is equivalent to the following OMT DIF
<simpleData name="newType" representation="WorldLocationStruct"/>

class HLAenumerated( name, representation, {enumeratorName:value})
Defines an enumeration.

HLAboolean = fom.HLAenumerated("HLAboolean",
    HLAinteger32BE, {"HLAfalse":0, "HLAtrue":1})
is equivalent to the following OMT DIF
<enumeratedData name="HLAboolean" representation="HLAinteger32BE">
    <enumerator name="HLAfalse" values="0"/>
    <enumerator name="HLAtrue" values="1"/>
</enumeratedData>

The enumerators are accessible via attributes. The values behave like integers, but don't support arithmetic.

print HLAboolean.HLAtrue

The pack function takes an enumerator, or an integer value.

encodedValue = fom.HLAboolean.pack(HLAboolean.HLAtrue)

class HLAfixedArray( name, elementType, cardinality)
Defines a fixed-length array.

arrayType = fom.HLAfixedArray("arrayType", fom.HLAfloat32LE, 3)
is equivalent to the following OMT DIF
<arrayData name="arrayType"
    encoding="HLAfixedArray" dataType="HLAfloat32LE" cardinality="3"/>

The pack function takes a sequence object.

encodedValue = fom.arrayType.pack([3.14, 17, 42])

class HLAvariableArray( name, elementType, cardinality = None)
Defines a variable-length array.

Dynamic cardinality is represented by the None value.

newType = fom.HLAvariableArray("newType", fom.HLAinteger16BE, None)
is equivalent to the following OMT DIF
<arrayData name="newType"
    encoding="HLAvariableArray" dataType="HLAinteger16BE" cardinality="Dynamic"/>

The hla.omt module defines the following variable arrays.

type name element type
HLAASCIIstring HLAoctet

class HLAfixedRecord( name, [(fieldName, fieldType)])
Defines a fixed record.

recordType = fom.HLAfixedRecord("recordType",
    [('X',fom.HLAinteger16BE), ('Y',fom.HLAfloat32BE)])
is equivalent to the following OMT DIF
<fixedRecordData name="recordType">
    <field name="X" dataType="HLAinteger16BE"/>
    <field name="Y" dataType="HLAfloat32BE"/>
</fixedRecordData>

The pack function takes a mapping object.

encodedValue = fom.recordType.pack({'X':0, 'Y':3.12})

class HLAvariantRecord( name, (discriminant, dataType), [([enumerators], altName, altType)])
Defines a variant record.

recordType = fom.HLAvariantRecord("recordType", ("Axis",AxisEnum),
    [(["TX"],"X",HLAinteger32LE), (["TY",None],"Y",HLAinteger32LE)])
is equivalent to the following OMT DIF
<variantRecordData name="recordType"
    encoding="HLAvariantRecord" dataType="AxisEnum" discriminant="Axis">
    <alternative enumerator="TX" name="X" dataType="HLAinteger32LE"/>
    <alternative enumerator="TY,HLAother" name="Y" dataType="HLAinteger32LE"/>
</variantRecordData>

The HLAother enumerator is represented by the None value.

The pack function takes a mapping object.

encodedValue = fom.recordType.pack({'Axis':AxisEnum.TX, 'X':7.2})