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.
) |
value) |
encodedValue = fom.HLAfloat64LE.pack(3.14) encodedValue += fom.HLAinteger16BE.pack(42)
value) |
value1, offset2 = fom.HLAfloat64LE.unpack(encodedValue) value2, offset3 = fom.HLAinteger16BE.unpack(encodedValue[offset2:]) print value1, value2
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.
filename) |
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)
typename) |
newType = fom.HLAencoding('WorldLocationStruct')
<simpleData name="newType" representation="WorldLocationStruct"/>
name, representation, {enumeratorName:value}) |
HLAboolean = fom.HLAenumerated("HLAboolean", HLAinteger32BE, {"HLAfalse":0, "HLAtrue":1})
<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)
name, elementType, cardinality) |
arrayType = fom.HLAfixedArray("arrayType", fom.HLAfloat32LE, 3)
<arrayData name="arrayType" encoding="HLAfixedArray" dataType="HLAfloat32LE" cardinality="3"/>
The pack function takes a sequence object.
encodedValue = fom.arrayType.pack([3.14, 17, 42])
name, elementType, cardinality = None) |
Dynamic cardinality is represented by the None value.
newType = fom.HLAvariableArray("newType", fom.HLAinteger16BE, None)
<arrayData name="newType" encoding="HLAvariableArray" dataType="HLAinteger16BE" cardinality="Dynamic"/>
The hla.omt module defines the following variable arrays.
type name | element type |
---|---|
HLAASCIIstring | HLAoctet |
name, [(fieldName, fieldType)]) |
recordType = fom.HLAfixedRecord("recordType", [('X',fom.HLAinteger16BE), ('Y',fom.HLAfloat32BE)])
<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})
name, (discriminant, dataType), [([enumerators], altName, altType)]) |
recordType = fom.HLAvariantRecord("recordType", ("Axis",AxisEnum), [(["TX"],"X",HLAinteger32LE), (["TY",None],"Y",HLAinteger32LE)])
<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})