1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#[allow(unused_imports)]
use crate::Type;

/// Errors encounterable while parsing a message from bytes
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
pub enum MessageParseError {
  /// Reached end of stream before parsing was finished
  UnexpectedEndOfStream,

  /// Token length was > 8
  InvalidTokenLength(u8),

  /// Error parsing option
  OptParseError(super::opt::parse_error::OptParseError),

  /// The rest of the message contained more bytes than there was capacity for
  PayloadTooLong(usize),

  /// The message type is invalid (see [`Type`] for information & valid values)
  InvalidType(u8),
}

impl MessageParseError {
  /// Shorthand for [`MessageParseError::UnexpectedEndOfStream`]
  pub fn eof() -> Self {
    Self::UnexpectedEndOfStream
  }
}