Skip to main content

Pdu

Trait Pdu 

Source
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§

Source

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§

Source

fn pdu_type(&self) -> PduType

The PDU’s type. It is fixed for each PDU struct, and serialize writes it into the header.

Source

fn protocol_family(&self) -> ProtocolFamily

The PDU’s protocol family. It is fixed for each PDU struct, and serialize writes it into the header.

Source

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

Source

fn header(&self) -> &Self::Header

The PDU’s header.

Source

fn header_mut(&mut self) -> &mut Self::Header

A mutable reference to the PDU’s header to change its exercise ID, timestamp, or status.

Source

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.

Source

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

Source

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

Source

fn deserialize_without_header( buf: &mut &[u8], pdu_header: Self::Header, ) -> Result<Self, DISError>
where Self: Sized,

Decodes a PDU body from the front of buf using a header that has already been deserialized.

§Errors

Will return DISError if the PDU header provided is invalid

Provided Methods§

Source

fn to_bytes(&mut self) -> Result<Vec<u8>, DISError>

Encodes the PDU into a new buffer

§Errors

Will return DISError in the same case as serialize.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Pdu for AcknowledgePdu

Source§

impl Pdu for AcknowledgeReliablePdu

Source§

impl Pdu for ActionRequestPdu

Source§

impl Pdu for ActionRequestReliablePdu

Source§

impl Pdu for ActionResponsePdu

Source§

impl Pdu for ActionResponseReliablePdu

Source§

impl Pdu for AggregateStatePdu

Source§

impl Pdu for AppearancePdu

Source§

impl Pdu for ArealObjectStatePdu

Source§

impl Pdu for ArticulatedPartsPdu

Source§

impl Pdu for AttributePdu

Source§

impl Pdu for CollisionElasticPdu

Source§

impl Pdu for CollisionPdu

Source§

impl Pdu for CommentPdu

Source§

impl Pdu for CommentReliablePdu

Source§

impl Pdu for CreateEntityPdu

Source§

impl Pdu for CreateEntityReliablePdu

Source§

impl Pdu for DataPdu

Source§

impl Pdu for DataQueryPdu

Source§

impl Pdu for DataQueryReliablePdu

Source§

impl Pdu for DataReliablePdu

Source§

impl Pdu for DesignatorPdu

Source§

impl Pdu for DetonationPdu

Source§

impl Pdu for DirectedEnergyFirePdu

Source§

impl Pdu for ElectromagneticEmissionsPdu

Source§

impl Pdu for EntityDamageStatusPdu

Source§

impl Pdu for EntityStatePdu

Source§

impl Pdu for EntityStateUpdatePdu

Source§

impl Pdu for EnvironmentalProcessPdu

Source§

impl Pdu for EventReportPdu

Source§

impl Pdu for EventReportReliablePdu

Source§

impl Pdu for FirePdu

Source§

impl Pdu for GriddedDataPdu

Source§

impl Pdu for IFFPdu

Source§

impl Pdu for InformationOperationsActionPdu

Source§

impl Pdu for InformationOperationsReportPdu

Source§

impl Pdu for IntercomControlPdu

Source§

impl Pdu for IntercomSignalPdu

Source§

impl Pdu for IsGroupOfPdu

Source§

impl Pdu for IsPartOfPdu

Source§

impl Pdu for LinearObjectStatePdu

Source§

impl Pdu for LiveEntityDetonationPdu

Source§

impl Pdu for LiveEntityFirePdu

Source§

impl Pdu for MinefieldDataPdu

Source§

impl Pdu for MinefieldQueryPdu

Source§

impl Pdu for MinefieldResponseNackPdu

Source§

impl Pdu for MinefieldStatePdu

Source§

impl Pdu for PointObjectStatePdu

Source§

impl Pdu for ReceiverPdu

Source§

impl Pdu for RecordQueryReliablePdu

Source§

impl Pdu for RecordReliablePdu

Source§

impl Pdu for RemoveEntityPdu

Source§

impl Pdu for RemoveEntityReliablePdu

Source§

impl Pdu for RepairCompletePdu

Source§

impl Pdu for RepairResponsePdu

Source§

impl Pdu for ResupplyCancelPdu

Source§

impl Pdu for ResupplyOfferPdu

Source§

impl Pdu for ResupplyReceivedPdu

Source§

impl Pdu for ServiceRequestPdu

Source§

impl Pdu for SetDataPdu

Source§

impl Pdu for SetDataReliablePdu

Source§

impl Pdu for SetRecordReliablePdu

Source§

impl Pdu for SignalPdu

Source§

impl Pdu for StartResumePdu

Source§

impl Pdu for StartResumeReliablePdu

Source§

impl Pdu for StopFreezePdu

Source§

impl Pdu for StopFreezeReliablePdu

Source§

impl Pdu for SupplementalEmissionPdu

Source§

impl Pdu for TimeSpacePositionInformationPdu

Source§

impl Pdu for TransferOwnershipPdu

Source§

impl Pdu for TransmitterPdu

Source§

impl Pdu for UnderwaterAcousticPdu