1use std::fmt::Display;
2
3use nom::error::{ErrorKind, ParseError};
4
5use crate::constants::AddressFamilyId;
6
7#[derive(Debug, Default)]
8pub struct ParserContext {
9 pub four_octet_asn: Option<bool>,
11 pub address_family: Option<AddressFamilyId>,
13}
14
15#[derive(Debug)]
16pub enum ToWireError {
17 OutBufferOverflow,
19 Other(eyre::Error),
21}
22
23impl Display for ToWireError {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self {
26 ToWireError::OutBufferOverflow => write!(f, "OutBufferOverflow"),
27 ToWireError::Other(report) => report.fmt(f),
28 }
29 }
30}
31
32impl std::error::Error for ToWireError {}
33
34#[derive(Debug)]
36pub enum BgpParserError<I> {
37 ProtocolError(ProtocolErrorValues),
40 CustomText(&'static str),
41 Eyre(eyre::ErrReport),
42 Nom(I, ErrorKind),
43}
44
45impl<I> ParseError<I> for BgpParserError<I> {
46 fn from_error_kind(input: I, kind: ErrorKind) -> Self {
47 BgpParserError::Nom(input, kind)
48 }
49 fn append(_: I, _: ErrorKind, other: Self) -> Self {
50 other
51 }
52}
53
54#[derive(Debug)]
55pub enum ProtocolErrorValues {
56 UnsupportedVersion(u8),
59 UnknownOpenOption(u8),
61}