pub struct DnodeParser { /* private fields */ }Expand description
Streaming DNODE header parser.
Implementations§
Source§impl DnodeParser
impl DnodeParser
Sourcepub fn new() -> Self
pub fn new() -> Self
Build a fresh parser positioned at DynParseState::Start.
§Examples
use dynomite::proto::dnode::{DnodeParser, DynParseState};
let p = DnodeParser::new();
assert_eq!(p.state(), DynParseState::Start);Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the parser to DynParseState::Start with a fresh
accumulator Dmsg.
Sourcepub fn state(&self) -> DynParseState
pub fn state(&self) -> DynParseState
Current state.
Sourcepub fn take_dmsg(&mut self) -> Dmsg
pub fn take_dmsg(&mut self) -> Dmsg
Move the parsed Dmsg out of the parser. Only meaningful
after a ParseStep::HeaderDone step.
Sourcepub fn step(&mut self, input: &[u8]) -> ParseStep
pub fn step(&mut self, input: &[u8]) -> ParseStep
Feed input to the parser. The parser advances as far as it
can and returns one of the three ParseStep variants.
The state machine is byte-driven and can be reentered with a
fresh slice when ParseStep::NeedMore indicates the input
was truncated mid-header.
§Examples
use dynomite::proto::dnode::{DnodeParser, ParseStep};
let mut p = DnodeParser::new();
let bytes = b"$2014$ 1 3 0 1 1 *1 d *0\r\n";
match p.step(bytes) {
ParseStep::HeaderDone { consumed } => assert_eq!(consumed, bytes.len()),
other => panic!("unexpected: {other:?}"),
}The state machine intentionally stays in one function to match the reference engine’s single-block parser; splitting the per-state arms across helpers would obscure the parity.
Trait Implementations§
Source§impl Debug for DnodeParser
impl Debug for DnodeParser
Auto Trait Implementations§
impl Freeze for DnodeParser
impl RefUnwindSafe for DnodeParser
impl Send for DnodeParser
impl Sync for DnodeParser
impl Unpin for DnodeParser
impl UnsafeUnpin for DnodeParser
impl UnwindSafe for DnodeParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more