dis_rust/common/pdu.rs
1// dis-rust - A rust implementation of the DIS simulation protocol.
2// Copyright (C) 2022 Thomas Mann
3//
4// This software is dual-licensed. It is available under the conditions of
5// the GNU Affero General Public License (see the LICENSE file included)
6// or under a commercial license (email contact@coffeebreakdevs.com for
7// details).
8
9use std::any::Any;
10
11use bytes::BytesMut;
12
13use super::{dis_error::DISError, pdu_header_record::PDUHeaderRecord};
14
15/// Trait to denote a PDU.
16pub trait PDU {
17 /// Fills a BytesMut struct with a PDU serialised into binary. This buffer is then ready to be sent via
18 /// UDP to the simluation network.
19 fn serialise(&self, buf: &mut BytesMut);
20
21 /// Creates a PDU from a BytesMut struct.
22 fn deserialise(buffer: BytesMut) -> Result<Self, DISError> where Self: Sized;
23
24 /// Creates a PDU from a BytesMut struct.
25 fn deserialise_without_header(buffer: BytesMut, pdu_header: PDUHeaderRecord) -> Result<Self, DISError> where Self: Sized;
26
27 fn as_any(&self) -> &dyn Any;
28}