pub struct ReaderConfig {
pub max_segment_bytes: usize,
pub max_segments: Option<usize>,
pub max_input_bytes: Option<u64>,
pub max_messages: Option<usize>,
}Expand description
Configuration for reader-based EDIFACT parsers.
Pass to from_reader_with_config or from_bufread_stream_with_config to
override default limits.
§Example
use edifact_rs::{ReaderConfig, from_reader_with_config};
let cfg = ReaderConfig::default().max_segment_bytes(4_096);
let segments: Vec<_> = from_reader_with_config(b"BGM+220+1+9'".as_ref(), cfg)
.collect::<Result<_, _>>()
.unwrap();
assert_eq!(segments[0].tag, "BGM");Fields§
§max_segment_bytes: usizeMaximum allowed segment byte length (excluding the segment terminator).
If a segment accumulates more bytes than this limit without a terminator
the parser returns EdifactError::SegmentTooLong. This prevents
unbounded allocation when processing malformed or adversarially crafted
input streams.
Default: 65 536 bytes (64 KiB). Real-world EDIFACT segments are almost always below 4 KiB; consider using a tighter limit for untrusted inputs.
max_segments: Option<usize>Maximum number of segments to yield before the stream stops.
Once this many segments have been produced the segment stream returns
None, effectively truncating the message. Useful for preventing
resource exhaustion when the total segment count in a message is expected
to be bounded.
Default: None (unlimited).
max_input_bytes: Option<u64>Maximum total input bytes to consume before the stream stops.
The budget is checked before each segment is read. If
bytes_consumed >= max_input_bytes at that point the stream stops
immediately without reading any further data. A segment whose bytes
push bytes_consumed above the threshold is still yielded (parsing
cannot be abandoned mid-segment), but no subsequent segment will be
started. Use in combination with max_segment_bytes for
defence-in-depth against maliciously large inputs.
Default: None (unlimited).
max_messages: Option<usize>Maximum number of EDIFACT messages (UNH/UNT pairs) to process before the stream stops.
Once this many complete messages have been yielded the stream returns
None. Useful for rate-limiting or sampling large interchanges without
parsing the entire file.
Default: None (unlimited).
Implementations§
Source§impl ReaderConfig
impl ReaderConfig
Sourcepub fn max_segment_bytes(self, limit: usize) -> ReaderConfig
pub fn max_segment_bytes(self, limit: usize) -> ReaderConfig
Set the maximum segment byte length and return self.
Sourcepub fn max_segments(self, limit: usize) -> ReaderConfig
pub fn max_segments(self, limit: usize) -> ReaderConfig
Set the maximum number of segments to yield and return self.
Sourcepub fn max_input_bytes(self, limit: u64) -> ReaderConfig
pub fn max_input_bytes(self, limit: u64) -> ReaderConfig
Set the maximum total input bytes to consume and return self.
Sourcepub fn max_messages(self, limit: usize) -> ReaderConfig
pub fn max_messages(self, limit: usize) -> ReaderConfig
Set the maximum number of EDIFACT messages (UNH/UNT pairs) to yield and return self.
Trait Implementations§
Source§impl Clone for ReaderConfig
impl Clone for ReaderConfig
Source§fn clone(&self) -> ReaderConfig
fn clone(&self) -> ReaderConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more