open_dis_rust/common/
pdu.rs

1//     open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2//                     Simulation (DIS) application protocol
3//     Copyright (C) 2023 Cameron Howell
4//
5//     Licensed under the BSD 2-Clause License
6
7use super::{dis_error::DISError, pdu_header::PduHeader};
8use bytes::BytesMut;
9use std::any::Any;
10
11pub trait Pdu {
12    fn serialize(&mut self, buf: &mut BytesMut);
13    /// # Errors
14    ///
15    /// Will return `DISError` if the PDU header provided is invalid
16    fn deserialize(buffer: BytesMut) -> Result<Self, DISError>
17    where
18        Self: Sized;
19    /// # Errors
20    ///
21    /// Will return `DISError` if the PDU header provided is invalid
22    fn deserialize_without_header(
23        buffer: BytesMut,
24        pdu_header: PduHeader,
25    ) -> Result<Self, DISError>
26    where
27        Self: Sized;
28    fn as_any(&self) -> &dyn Any;
29}