Class DatasetMarshaller

java.lang.Object
com.trdp.config.DatasetMarshaller

public class DatasetMarshaller extends Object
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 Details

    • from

      public static DatasetMarshaller from(DeviceConfig config)
      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

      public byte[] marshall(int comId, Map<String,Object> values)
      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 ID
      values - field name to value mapping
      Returns:
      the encoded binary payload
      Throws:
      IllegalArgumentException - if no dataset is registered for the ComID
    • unmarshall

      public TrdpDataset unmarshall(int comId, byte[] data)
      Decodes a binary payload into a TrdpDataset for the given ComID.
      Parameters:
      comId - the communication ID
      data - 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

      public List<TrdpDataset.FieldDefinition> getSchema(int comId)
      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