use crate::output_stream::num_bytes::NumBytes;
use typed_builder::TypedBuilder;
pub const DEFAULT_MAX_LINE_LENGTH: NumBytes = NumBytes(16 * 1024);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LineOverflowBehavior {
#[default]
DropAdditionalData,
EmitAdditionalAsNewLines,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, TypedBuilder)]
pub struct LineParsingOptions {
pub max_line_length: NumBytes,
pub overflow_behavior: LineOverflowBehavior,
pub buffer_compaction_threshold: Option<NumBytes>,
}
impl Default for LineParsingOptions {
fn default() -> Self {
Self {
max_line_length: DEFAULT_MAX_LINE_LENGTH,
overflow_behavior: LineOverflowBehavior::default(),
buffer_compaction_threshold: None,
}
}
}
pub(crate) fn assert_max_line_length_non_zero(options: &LineParsingOptions) {
assert!(
options.max_line_length.bytes() > 0,
"LineParsingOptions::max_line_length must be greater than zero. \
If you want effectively unbounded line parsing, pass `NumBytes::MAX` (or another \
large explicit value) — zero is never a valid configuration for line-consuming \
visitors."
);
}