dis_rs/common/
errors.rs

1use thiserror::Error;
2
3use crate::constants::PDU_HEADER_LEN_BYTES;
4
5#[derive(Debug, PartialEq, Eq, Error)]
6pub enum DisError {
7    // UnsupportedProtocolVersion,
8    #[error("{0}")]
9    ParseError(String), // the parsing of a PDU resulted in an error
10    #[error("The buffer does not contain enough bytes for a valid DIS header. {0} bytes available, needed {PDU_HEADER_LEN_BYTES}")]
11    InsufficientHeaderLength(u16), // the input was too small to contain a valid DIS header; (u16 found)
12    #[error("PDU has insufficient length. Expected {0}, found {1}")]
13    InsufficientPduLength(u16, u16), // the input was too small to contain a valid DIS Pdu based on the header and parsing; (u16 expected, u16 found)
14    #[error("PDU is larger than size of the buffer for serialisation. Needs {0} bytes, available {1} bytes")]
15    InsufficientBufferSize(u16, usize), // the buffer for serialisation has insufficient capacity to hold the provided PDU; (u16 PDU size, usize available capacity)
16    #[error("Provided String is not valid ASCII encoded.")]
17    StringNotAsciiError, // the String value to serialize is not valid ASCII encoded
18    #[error("Provided String is too long.")]
19    StringTooLongError, // the String value to serialize is too large for the field specification
20    #[error("IFF PDU - Incorrect System Time provided.")]
21    IffIncorrectSystemType, // the System Type in an IFF PDU is incorrect (to determine the type for parsing the basic data)
22    #[error("IFF PDU - Undetermined System Time.")]
23    IffUndeterminedSystemType, // the System Type in an IFF PDU does not determine whether it is an Interrogator or a Transponder
24}