flowparser_sflow/
error.rs1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub enum SflowError {
7 Incomplete {
9 available: usize,
11 context: String,
13 },
14 UnsupportedVersion {
16 version: u32,
18 },
19 ParseError {
21 offset: usize,
23 context: String,
25 kind: String,
27 },
28 TooManySamples {
30 count: u32,
32 max: u32,
34 },
35}
36
37impl fmt::Display for SflowError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 SflowError::Incomplete { available, context } => {
41 write!(
42 f,
43 "Incomplete data: only {available} bytes available ({context})"
44 )
45 }
46 SflowError::UnsupportedVersion { version } => {
47 write!(f, "Unsupported sFlow version: {version} (expected 5)")
48 }
49 SflowError::ParseError {
50 offset,
51 context,
52 kind,
53 } => {
54 write!(f, "Parse error at offset {offset}: {kind} ({context})")
55 }
56 SflowError::TooManySamples { count, max } => {
57 write!(f, "Too many samples: {count} exceeds maximum of {max}")
58 }
59 }
60 }
61}
62
63impl std::error::Error for SflowError {}