pub struct NetconfCodec { /* private fields */ }Implementations§
Source§impl NetconfCodec
tokio_util codec for NETCONF message framing.
impl NetconfCodec
tokio_util codec for NETCONF message framing.
Implements the Decoder trait from tokio_util, which defines how to
extract discrete messages from a continuous TCP byte stream.
We don’t call decode() directly. Instead, we pass this codec to
FramedRead, which handles the I/O loop:
let reader = FramedRead::new(read_half, NetconfCodec::new(…)); while let Some(msg) = reader.next().await { … }
FramedRead reads bytes from the network into an internal buffer,
calls our decode() to check for a complete message, and yields
messages as a Stream. We only need to implement the framing logic –
“is there a complete message in this buffer?” – and FramedRead
handles everything else (buffer management, read loops, EOF).
decode() is called repeatedly. It owns the internal buffer. When decode() returns Ok(None), FramedRead reads more bytes from the underlying AsyncRead into the buffer and calls decode() again. When decode() returns Ok(Some(item)), the item is yielded to the consumer. The key invariant is: decode() must consume (via split_to() or advance()) exactly the bytes belonging to the returned message. Any leftover bytes in src remain for the next decode() call.
Returns Bytes (not String) because UTF-8 validation is deferred
to the XML parser. This avoids a redundant O(n) validation pass at
the framing layer