Expand description
HLA data encoding helpers of IEEE 1516-2025: the encoding package of the standard Java and C++ APIs
(12.11.4.2, 12.12.4.2) as a Rust library.
Attribute and parameter values are opaque octets for the RTI. Federates agree on their layout through the datatypes of the FOM, whose encodings are defined by IEEE 1516.2 (OMT). This crate implements those encodings, including the padding rules, in two layers.
§Typed layer
Encode and Decode are implemented by Rust types whose HLA datatype is known at compile time:
- the basic representations as wrappers of the Rust type they carry:
HLAinteger32BE(i32),HLAfloat64LE(f64),HLAoctet(u8)…; - the simple datatypes
HLAASCIIchar,HLAunicodeChar,HLAbyte,HLAboolean; HLAASCIIstring,HLAunicodeString(alsoString),HLAopaqueData;- the handle elements (
HLAfederateHandle…) andHLAlogicalTime,HLAlogicalTimeInterval; Vec<T>(HLAvariableArray) and[T; N](HLAfixedArray);- structs and enums declared with
hla_fixed_record!,hla_enumerated!,hla_variant_record!andhla_extendable_variant_record!.
Bare integers and floats have no encoding of their own because the datatype decides size and byte
order; the macros accept them with an encoding marker (speed: f32 as HLAfloat32BE).
use microrti_encoding::{
decode_from_slice_strict, encode_to_vec, hla_fixed_record, DecoderError, HLAfloat64BE, HLAoctet,
};
hla_fixed_record! {
/// A position report.
pub struct Report {
pub quality: HLAoctet,
pub position: [HLAfloat64BE; 2],
pub label: String,
}
}
let report = Report {
quality: HLAoctet(3),
position: [HLAfloat64BE(1.0), HLAfloat64BE(-2.0)],
label: "x".into(),
};
let bytes = encode_to_vec(&report);
// 1 octet, 7 of padding, 2 x 8 octets, a count and one UTF-16 code unit.
assert_eq!(bytes.len(), 1 + 7 + 16 + 4 + 2);
assert_eq!(decode_from_slice_strict::<Report>(&bytes)?, report);§Dynamic layer
DataElement is the object-safe trait of the standard APIs. Every typed value is a data element,
and the containers HLAfixedRecord, HLAfixedArray, HLAvariableArray, HLAvariantRecord
and HLAextendableVariantRecord assemble datatypes at run time, for example from a parsed FOM.
use microrti_encoding::{
DataElement, HLAboolean, HLAfixedRecord, HLAinteractionClassHandle, HLAvariableArray,
};
// MOM datatype HLAinteractionSubList: a variable array of HLAinteractionSubscription records.
let subscription = |class: [u8; 4], active: bool| {
HLAfixedRecord::new().with(HLAinteractionClassHandle::new(class)).with(HLAboolean(active))
};
let mut list = HLAvariableArray::new(subscription([0; 4], false));
list.push(subscription([0, 0, 0, 9], true))?;
let bytes = list.to_bytes()?;
assert_eq!(bytes, [0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 9, 0, 0, 0, 1]);
let mut decoded = HLAvariableArray::new(subscription([0; 4], false));
decoded.decode_slice_strict(&bytes)?;
assert_eq!(decoded, list);§Padding
Every datatype has an octet boundary, and its encoding starts at an offset, counted from the start of
the outermost value, that is a multiple of it. Here each element aligns itself before it writes or
reads, which yields the padding the standard places between the parts of a constructed datatype and
none after the last part. ByteWriter and ByteReader keep track of the offset.
§Robustness
Decoding never panics. Errors are DecoderError values, element counts are checked against the
octets that are left before anything is allocated, and memory use is bounded by a small multiple of
the input size.
§FOM-driven codec
With the cargo feature fom the module fom adds a third layer: FomCodec encodes and decodes
any data type of a merged FDD (microrti-fom) by its name, to and from a self-describing Value
tree. The feature is off by default, and the default build does not depend on microrti-fom.
Modules§
- extendable
- Wire layout of
HLAextendableVariantRecord, the variant record encoding introduced in 2025 so that FOM modules can add alternatives to an existing datatype.
Macros§
- hla_
enumerated - Declares an enumerated datatype: a fieldless enum carried by a basic representation.
- hla_
extendable_ variant_ record - Declares an
HLAextendableVariantRecorddatatype as a Rust enum. - hla_
fixed_ record - Declares an
HLAfixedRecorddatatype as a Rust struct. - hla_
variant_ record - Declares an
HLAvariantRecorddatatype as a Rust enum.
Structs§
- Byte
Reader - Source of a decoding: a cursor over a byte slice.
- Byte
Writer - Destination of an encoding.
- Fixed
Array Of - Encoding marker for
[V; N]carried as anHLAfixedArraywhose elements use the markerR. - HLAASCI
Ichar HLAASCIIchar: one ASCII character carried in anHLAoctet. The value is not range checked.- HLAASCI
Istring HLAASCIIstring: anHLAvariableArrayofHLAASCIIchar, one octet per character.- HLAattribute
Handle HLAattributeHandle: the encoded form of an attribute handle.- HLAboolean
HLAboolean: the enumerated datatypeHLAfalse= 0,HLAtrue= 1 carried in anHLAinteger32BE.- HLAbyte
HLAbyte: one uninterpreted 8-bit byte carried in anHLAoctet.- HLAdimension
Handle HLAdimensionHandle: the encoded form of a dimension handle.- HLAextendable
Variant Record HLAextendableVariantRecord: a variant record whose encoding states the length of the alternative, so that a receiver skips alternatives it does not know and other FOM modules can add alternatives.- HLAfederate
Handle HLAfederateHandle: the encoded form of a federate handle.- HLAfixed
Array HLAfixedArray: a fixed number of elements of one datatype, encoded in order without a count. The octet boundary is the boundary of the element datatype.- HLAfixed
Record HLAfixedRecord: fields of any datatypes, encoded in order, each at its own octet boundary. Nothing follows the last field. The octet boundary of the record is the largest boundary of its fields.- HLAfloat32BE
HLAfloat32BE: IEEE 754 single precision, big endian.- HLAfloat32LE
HLAfloat32LE: IEEE 754 single precision, little endian.- HLAfloat64BE
HLAfloat64BE: IEEE 754 double precision, big endian.- HLAfloat64LE
HLAfloat64LE: IEEE 754 double precision, little endian.- HLAinteger16BE
HLAinteger16BE: 16-bit two’s complement integer, big endian.- HLAinteger16LE
HLAinteger16LE: 16-bit two’s complement integer, little endian.- HLAinteger32BE
HLAinteger32BE: 32-bit two’s complement integer, big endian.- HLAinteger32LE
HLAinteger32LE: 32-bit two’s complement integer, little endian.- HLAinteger64BE
HLAinteger64BE: 64-bit two’s complement integer, big endian.- HLAinteger64LE
HLAinteger64LE: 64-bit two’s complement integer, little endian.- HLAinteraction
Class Handle HLAinteractionClassHandle: the encoded form of an interaction class handle.- HLAlogical
Time HLAlogicalTime: the encoded form of a logical time.- HLAlogical
Time Interval HLAlogicalTimeInterval(MIM datatypeHLAtimeInterval): the encoded form of a time interval.- HLAmessage
Retraction Handle HLAmessageRetractionHandle: the encoded form of a message retraction handle.- HLAobject
Class Handle HLAobjectClassHandle: the encoded form of an object class handle.- HLAobject
Instance Handle HLAobjectInstanceHandle: the encoded form of an object instance handle.- HLAoctet
HLAoctet: one uninterpreted octet.- HLAoctet
PairBE HLAoctetPairBE: two octets, most significant first.- HLAoctet
PairLE HLAoctetPairLE: two octets, least significant first.- HLAopaque
Data HLAopaqueData: anHLAvariableArrayofHLAbyte(32-bit big-endian count, then the octets).- HLAparameter
Handle HLAparameterHandle: the encoded form of a parameter handle.- HLAregion
Handle HLAregionHandle: the encoded form of a region handle.- HLAtransportation
Type Handle HLAtransportationTypeHandle: the encoded form of a transportation type handle.- HLAunicode
Char HLAunicodeChar: one UTF-16 code unit carried in anHLAoctetPairBE.- HLAunicode
String HLAunicodeString: anHLAvariableArrayofHLAunicodeChar, that is UTF-16 code units in big-endian order. The count is the number of code units; characters outside the BMP take a surrogate pair.- HLAunsigned
Integer8 HLAunsignedInteger8: 8-bit unsigned integer (MIM basic representation new in 2025).- HLAunsigned
Integer16BE HLAunsignedInteger16BE: 16-bit unsigned integer, big endian.- HLAunsigned
Integer16LE HLAunsignedInteger16LE: 16-bit unsigned integer, little endian.- HLAunsigned
Integer32BE HLAunsignedInteger32BE: 32-bit unsigned integer, big endian.- HLAunsigned
Integer32LE HLAunsignedInteger32LE: 32-bit unsigned integer, little endian.- HLAunsigned
Integer64BE HLAunsignedInteger64BE: 64-bit unsigned integer, big endian.- HLAunsigned
Integer64LE HLAunsignedInteger64LE: 64-bit unsigned integer, little endian.- HLAvariable
Array HLAvariableArray: the element count asHLAinteger32BE, then the elements of one datatype, each at its own octet boundary. An empty array is the count alone. The octet boundary is the larger of 4 and the boundary of the element datatype.- HLAvariant
Record HLAvariantRecord: the discriminant, padding to the largest octet boundary of all alternatives, then the alternative selected by the discriminant. A discriminant without alternative data is encoded alone. The octet boundary is the largest boundary of the discriminant and of all alternatives.- Variable
Array Of - Encoding marker for
Vec<V>carried as anHLAvariableArraywhose elements use the markerR.
Enums§
- Decoder
Error - Reasons why a byte sequence cannot be decoded.
- Encoder
Error - Reasons why a value cannot be encoded.
Traits§
- Basic
Data - A basic data representation wrapping one native Rust value (
HLAinteger32BEwrapsi32). - Data
Element - A value that knows its HLA encoding at run time.
- Decode
- A Rust type that can be rebuilt from its HLA encoding.
- Encode
- A Rust type with a fixed HLA encoding.
- Enumerated
- A datatype usable as the discriminant of a variant record: an enumerated datatype, or a basic representation used directly.
- Representation
- An encoding marker:
Selfnames the HLA datatype used to carry Rust values of typeV.
Functions§
- decode_
from_ slice - Decodes one value from the start of
bytes; octets after the value are ignored. - decode_
from_ slice_ strict - Decodes one value that must span
bytesexactly: trailing octets areDecoderError::TrailingBytes. - decode_
prefix - Decodes one value from the start of
bytesand returns it with the number of octets it used. - encode_
into - Appends the encoding of
valuetobufferas a new outermost value: padding is computed from the first appended octet, whateverbufferalready holds. On errorbufferis left unchanged. - encode_
to_ vec - Encodes
valueas an outermost value. - max_
boundary - Largest of the given octet boundaries, 1 for an empty list. Usable in constants.
- padding_
for - Number of padding octets needed at
offsetto reach the next multiple ofboundary. - try_
encode_ to_ vec - Encodes
valueas an outermost value, reporting values that have no encoding.
Type Aliases§
- DynElement
- A data element behind a pointer, with the
'staticbound every element has anyway. - HLAcount
- MIM simple datatype
HLAcount. - HLAfloat64
Time - MIM simple datatype
HLAfloat64Time: a bare logical time of the float representation (12.4). - HLAindex
- MIM simple datatype
HLAindex. - HLAinteger64
Time - MIM simple datatype
HLAinteger64Time: a bare logical time of the integer representation (12.4). - HLAmsec
- MIM simple datatype
HLAmsec. - HLAnormalized
Federate Handle - MIM simple datatype
HLAnormalizedFederateHandle. - HLAnormalized
Interaction Class Handle - MIM simple datatype
HLAnormalizedInteractionClassHandle. - HLAnormalized
Object Class Handle - MIM simple datatype
HLAnormalizedObjectClassHandle. - HLAnormalized
Object Instance Handle - MIM simple datatype
HLAnormalizedObjectInstanceHandle. - HLAseconds
- MIM simple datatype
HLAseconds. - HLAtoken
- MIM array datatype
HLAtoken: anHLAfixedArrayof zeroHLAbyte, encoded as nothing at all. - HLAupdate
Rate Name - MIM array datatype
HLAupdateRateName.