pub struct Decoder { /* private fields */ }Expand description
Protocol decoder.
Decoder holds an internal buffer and reads from an underlying stream
until a complete protocol frame or command can be parsed. It enforces a
maximum buffer size to protect against oversized messages.
Typical usage:
use xvc_protocol::{Message, XvcInfo};
use std::io::Cursor;
// Read a single message from a byte stream
let mut data = b"getinfo:".as_slice();
let mut dec = xvc_protocol::rw::Decoder::new(1024);
let msg = dec.read_message(&mut data).unwrap();
assert!(matches!(msg, Message::GetInfo));Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new(max_shift: usize) -> Self
pub fn new(max_shift: usize) -> Self
Create a new decoder for reading protocol Messages.
max_shift is the maximum number of bytes allowed for each of the TMS
and TDI vectors in a Shift command. The internal buffer is sized to
accommodate the full shift payload.
Sourcepub fn read_xvc_info(
&mut self,
reader: &mut impl Read,
) -> Result<XvcInfo, ReadError>
pub fn read_xvc_info( &mut self, reader: &mut impl Read, ) -> Result<XvcInfo, ReadError>
Read an XvcInfo frame from reader.
This method incrementally fills the internal buffer from reader until
a complete XVC server info frame is available and returns the parsed
XvcInfo. If EOF is encountered with partial data buffered, a
ReadError::InvalidCommand is returned.
Sourcepub fn read_message(
&mut self,
reader: &mut impl Read,
) -> Result<OwnedMessage, ReadError>
pub fn read_message( &mut self, reader: &mut impl Read, ) -> Result<OwnedMessage, ReadError>
Read a single protocol Message from reader.
The decoder reads from reader until a full command and its payload
are available, enforces negotiated limits (e.g. maximum shift buffer
size) and returns the parsed Message. On EOF with a partial
command present, a ReadError::InvalidCommand is returned.
Example:
use std::io::Cursor;
let mut cursor = Cursor::new(b"getinfo:");
let mut dec = xvc_protocol::rw::Decoder::new(1024);
let msg = dec.read_message(&mut cursor).unwrap();
assert!(matches!(msg, xvc_protocol::Message::GetInfo));