psas_packet API

Message Class

The message class can be initialized with information about the data that can be packed in it. This will make an object with encode and decode methods available for packing and unpacking.

class psas_packet.messages.Message(definition)

Definition of a message type

Parameters:definition (dict) – Dictionary defining data in a message
Returns:Message instance

Suitable metadata can be passed in and this class will perform necessary pre-compute steps and create a usable message instance for a specific data source.


Decode a single message body (the data lines). Header info and message boundaries are solved in network

Parameters:raw (bytestr) – Raw string of bytes the length of
Returns:A dictionary of values in normal units

Encode a set of data into binary

Parameters:data (dict) – A dictionary of values to encode
Returns:Binary ecoded data

Uses the struct package to encode into byte array. The dictionary should have values who’s keys match the members list.


Autogen c style typedef structs

Returns:String c code for the data and header for this packet


class psas_packet.messages.MessageSizeError(expected, got)

Raised when the byte str to be unpacked does not match the expected size for this type. Check your message boundaries.

  • expected (int) – correct size
  • got (int) – attempted size

MessageSizeError exception