Skip to main content

dis_rs/common/
errors.rs

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