Class DatasetMarshaller
java.lang.Object
com.trdp.config.DatasetMarshaller
Registry that maps ComIDs to dataset schemas and provides automatic
marshalling (encode) and unmarshalling (decode) of structured payloads.
Built from a DeviceConfig, it resolves each telegram's
data-set-id to its DataSetDefinition and converts the
element types into TrdpDataType-based field schemas. Supports
nested dataset references and array elements.
Usage:
DeviceConfig config = TrdpConfig.load(Path.of("trdp-config.xml"));
DatasetMarshaller marshaller = DatasetMarshaller.from(config);
// Encode
byte[] payload = marshaller.marshall(1000, Map.of("speed", 42L, "doorOpen", true));
// Decode
TrdpDataset dataset = marshaller.unmarshall(1000, receivedBytes);
long speed = (Long) dataset.getValue("speed");
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DatasetMarshallerfrom(DeviceConfig config) Builds a marshaller from a device configuration.getSchema(int comId) Returns the field schema for the given ComID.booleanhasSchema(int comId) Returns whether a dataset schema is registered for the given ComID.byte[]Encodes field values into a binary payload for the given ComID.unmarshall(int comId, byte[] data) Decodes a binary payload into aTrdpDatasetfor the given ComID.
-
Method Details
-
from
Builds a marshaller from a device configuration. Resolves all telegram ComID-to-dataset mappings across all bus interfaces.- Parameters:
config- the parsed device configuration- Returns:
- a marshaller with schemas registered for all telegrams that reference datasets
-
marshall
Encodes field values into a binary payload for the given ComID. Values are encoded in the order defined by the dataset schema. Missing fields default to zero/false/epoch.- Parameters:
comId- the communication IDvalues- field name to value mapping- Returns:
- the encoded binary payload
- Throws:
IllegalArgumentException- if no dataset is registered for the ComID
-
unmarshall
Decodes a binary payload into aTrdpDatasetfor the given ComID.- Parameters:
comId- the communication IDdata- the binary payload to decode- Returns:
- the decoded dataset with named fields
- Throws:
IllegalArgumentException- if no dataset is registered for the ComID
-
hasSchema
public boolean hasSchema(int comId) Returns whether a dataset schema is registered for the given ComID.- Parameters:
comId- the communication ID- Returns:
- true if a schema exists
-
getSchema
Returns the field schema for the given ComID.- Parameters:
comId- the communication ID- Returns:
- unmodifiable list of field definitions
- Throws:
IllegalArgumentException- if no dataset is registered for the ComID
-