pub trait Pdu {
type Header: Copy + Debug + Default + PartialEq + Eq;
// Required methods
fn pdu_type(&self) -> PduType;
fn protocol_family(&self) -> ProtocolFamily;
fn calculate_length(&self) -> Result<u16, DISError>;
fn header(&self) -> &Self::Header;
fn header_mut(&mut self) -> &mut Self::Header;
fn finalize(&mut self);
fn serialize(&mut self, buf: &mut Vec<u8>) -> Result<(), DISError>;
fn deserialize(buf: &mut &[u8]) -> Result<Self, DISError>
where Self: Sized;
fn deserialize_without_header(
buf: &mut &[u8],
pdu_header: Self::Header,
) -> Result<Self, DISError>
where Self: Sized;
// Provided method
fn to_bytes(&mut self) -> Result<Vec<u8>, DISError> { ... }
}Expand description
A DIS Protocol Data Unit
Something that can be encoded to and decoded from the bytes of the DIS wire format
Required Associated Types§
Sourcetype Header: Copy + Debug + Default + PartialEq + Eq
type Header: Copy + Debug + Default + PartialEq + Eq
The PDU’s header: PduHeader for most PDUs, or LiveEntityPduHeader for the
Live Entity Information/Interaction family. StandardPdu and LiveEntityPdu
represent the two variants.
Required Methods§
Sourcefn pdu_type(&self) -> PduType
fn pdu_type(&self) -> PduType
The PDU’s type. It is fixed for each PDU struct, and serialize writes it into
the header.
Sourcefn protocol_family(&self) -> ProtocolFamily
fn protocol_family(&self) -> ProtocolFamily
The PDU’s protocol family. It is fixed for each PDU struct, and serialize writes
it into the header.
Sourcefn calculate_length(&self) -> Result<u16, DISError>
fn calculate_length(&self) -> Result<u16, DISError>
The PDU’s total encoded length in octets, header included
§Errors
Will return DISError if the calculated PDU length is greater than the maximum allowed size
Sourcefn header_mut(&mut self) -> &mut Self::Header
fn header_mut(&mut self) -> &mut Self::Header
A mutable reference to the PDU’s header to change its exercise ID, timestamp, or status.
Sourcefn finalize(&mut self)
fn finalize(&mut self)
Runs the PDU’s update rules and sets the header’s length without encoding it.
Errors are ignored here; serialize reports them.
Sourcefn serialize(&mut self, buf: &mut Vec<u8>) -> Result<(), DISError>
fn serialize(&mut self, buf: &mut Vec<u8>) -> Result<(), DISError>
Encodes the PDU and appends it to buf
Before encoding, this sets the header’s PDU type, protocol family, and length
along with every count, length, and flag field that depends on the PDU’s contents.
Anything already in buf is kept, so several PDUs can be written into one buffer.
§Errors
Will return DISError if serialization fails, especially if the dynamically calculated PDU
length is greater than the maximum allowed size
Sourcefn deserialize(buf: &mut &[u8]) -> Result<Self, DISError>where
Self: Sized,
fn deserialize(buf: &mut &[u8]) -> Result<Self, DISError>where
Self: Sized,
Decodes one PDU from the front of buf, advancing buf past it
Exactly the number of octets given by the header’s length field
are consumed, so anything after them, such as another bundled PDU,
is left in buf.
§Errors
Will return DISError if buf does not start with a valid PDU
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".