Skip to main content

Decoder

Struct Decoder 

Source
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

Source

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.

Source

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.

Source

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));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.