use crate::error::BgpValidationWarning;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS), ts(export))]
pub struct Span {
pub offset: u32,
pub length: u32,
}
impl Span {
pub const fn new(offset: u32, length: u32) -> Self {
Span { offset, length }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS), ts(export))]
pub struct DissectionNode {
pub field: String,
pub label: String,
pub offset: u32,
pub length: u32,
pub children: Vec<DissectionNode>,
}
impl DissectionNode {
pub fn new(
field: impl Into<String>,
label: impl Into<String>,
offset: u32,
length: u32,
) -> Self {
DissectionNode {
field: field.into(),
label: label.into(),
offset,
length,
children: Vec::new(),
}
}
pub const fn span(&self) -> Span {
Span {
offset: self.offset,
length: self.length,
}
}
pub fn find(&self, field: &str) -> Option<&DissectionNode> {
if self.field == field {
return Some(self);
}
self.children.iter().find_map(|child| child.find(field))
}
pub fn find_all<'a>(&'a self, field: &str, out: &mut Vec<&'a DissectionNode>) {
if self.field == field {
out.push(self);
}
for child in &self.children {
child.find_all(field, out);
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS), ts(export))]
pub struct SpannedWarning {
pub span: Span,
pub warning: BgpValidationWarning,
}