pub struct NetflowParserBuilder { /* private fields */ }Expand description
Builder for configuring and constructing a NetflowParser.
§Examples
use netflow_parser::NetflowParser;
use netflow_parser::variable_versions::ttl::TtlConfig;
use std::collections::HashSet;
use std::time::Duration;
let parser = NetflowParser::builder()
.with_cache_size(2000)
.with_ttl(TtlConfig::new(Duration::from_secs(7200)))
.with_allowed_versions([5, 9, 10].into())
.with_max_error_sample_size(512)
.build()
.expect("Failed to build parser");Implementations§
Source§impl NetflowParserBuilder
impl NetflowParserBuilder
Sourcepub fn with_cache_size(self, size: usize) -> Self
pub fn with_cache_size(self, size: usize) -> Self
Sourcepub fn with_v9_cache_size(self, size: usize) -> Self
pub fn with_v9_cache_size(self, size: usize) -> Self
Sets the V9 parser template cache size independently.
§Arguments
size- Maximum number of templates to cache (must be > 0)
Sourcepub fn with_ipfix_cache_size(self, size: usize) -> Self
pub fn with_ipfix_cache_size(self, size: usize) -> Self
Sets the IPFIX parser template cache size independently.
size- Maximum number of templates to cache (must be > 0)
Sourcepub fn with_ttl(self, ttl: TtlConfig) -> Self
pub fn with_ttl(self, ttl: TtlConfig) -> Self
Sets the TTL configuration for both V9 and IPFIX parsers.
§Arguments
ttl- TTL configuration (time-based)
§Examples
use netflow_parser::NetflowParser;
use netflow_parser::variable_versions::ttl::TtlConfig;
use std::time::Duration;
let parser = NetflowParser::builder()
.with_ttl(TtlConfig::new(Duration::from_secs(7200)))
.build()
.expect("Failed to build parser");Sourcepub fn with_v9_ttl(self, ttl: TtlConfig) -> Self
pub fn with_v9_ttl(self, ttl: TtlConfig) -> Self
Sets the TTL configuration for V9 parser independently.
Sourcepub fn with_ipfix_ttl(self, ttl: TtlConfig) -> Self
pub fn with_ipfix_ttl(self, ttl: TtlConfig) -> Self
Sets the TTL configuration for IPFIX parser independently.
Sourcepub fn with_allowed_versions(self, versions: HashSet<u16>) -> Self
pub fn with_allowed_versions(self, versions: HashSet<u16>) -> Self
Sets which Netflow versions are allowed to be parsed.
§Arguments
versions- Set of allowed version numbers (5, 7, 9, 10)
§Examples
use netflow_parser::NetflowParser;
// Only parse V9 and IPFIX
let parser = NetflowParser::builder()
.with_allowed_versions([9, 10].into())
.build()
.expect("Failed to build parser");Sourcepub fn with_max_error_sample_size(self, size: usize) -> Self
pub fn with_max_error_sample_size(self, size: usize) -> Self
Sourcepub fn register_enterprise_field(self, def: EnterpriseFieldDef) -> Self
pub fn register_enterprise_field(self, def: EnterpriseFieldDef) -> Self
Registers a custom enterprise field definition for both V9 and IPFIX parsers.
This allows library users to define their own enterprise-specific fields without modifying the library source code. Registered fields will be parsed according to their specified data type instead of falling back to raw bytes.
§Arguments
def- Enterprise field definition containing enterprise number, field number, name, and data type
§Examples
use netflow_parser::NetflowParser;
use netflow_parser::variable_versions::enterprise_registry::EnterpriseFieldDef;
use netflow_parser::variable_versions::data_number::FieldDataType;
let parser = NetflowParser::builder()
.register_enterprise_field(EnterpriseFieldDef::new(
12345, // Enterprise number
1, // Field number
"customMetric",
FieldDataType::UnsignedDataNumber,
))
.register_enterprise_field(EnterpriseFieldDef::new(
12345,
2,
"customApplicationName",
FieldDataType::String,
))
.build()
.expect("Failed to build parser");Sourcepub fn register_enterprise_fields(
self,
defs: impl IntoIterator<Item = EnterpriseFieldDef>,
) -> Self
pub fn register_enterprise_fields( self, defs: impl IntoIterator<Item = EnterpriseFieldDef>, ) -> Self
Registers multiple custom enterprise field definitions at once.
§Arguments
defs- Iterator of enterprise field definitions
§Examples
use netflow_parser::NetflowParser;
use netflow_parser::variable_versions::enterprise_registry::EnterpriseFieldDef;
use netflow_parser::variable_versions::data_number::FieldDataType;
let fields = vec![
EnterpriseFieldDef::new(12345, 1, "field1", FieldDataType::UnsignedDataNumber),
EnterpriseFieldDef::new(12345, 2, "field2", FieldDataType::String),
EnterpriseFieldDef::new(12345, 3, "field3", FieldDataType::Ip4Addr),
];
let parser = NetflowParser::builder()
.register_enterprise_fields(fields)
.build()
.expect("Failed to build parser");Sourcepub fn build(self) -> Result<NetflowParser, String>
pub fn build(self) -> Result<NetflowParser, String>
Builds the configured NetflowParser.
§Errors
Returns an error if:
- Template cache size is 0
- Parser initialization fails
§Examples
use netflow_parser::NetflowParser;
let parser = NetflowParser::builder()
.with_cache_size(2000)
.build()
.expect("Failed to build parser");Trait Implementations§
Source§impl Clone for NetflowParserBuilder
impl Clone for NetflowParserBuilder
Source§fn clone(&self) -> NetflowParserBuilder
fn clone(&self) -> NetflowParserBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more