Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

Reading cursor over a received buffer.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn new(buf: &'a [u8], pos: usize) -> Self

New reader positioned at pos within buf.

Source

pub fn remaining(&self) -> usize

Bytes remaining.

Source

pub fn pos(&self) -> usize

Current position relative to the start of buf.

Source

pub fn at_end(&self) -> bool

True when the cursor reached the end of the buffer.

Source

pub fn uint<const N: usize>(&mut self) -> Result<u64, ProtoError>

Read one unsigned little-endian integer of the given width.

Source

pub fn u8v(&mut self) -> Result<u8, ProtoError>

Read a single byte.

Source

pub fn skip(&mut self, n: usize)

Skip forward by n bytes (clamped to the end).

Source

pub fn take(&mut self, n: usize) -> Result<&'a [u8], ProtoError>

Borrow the next n bytes without copying.

Source

pub fn zstring(&mut self, unicode: bool, base: usize) -> String

Read a NUL-terminated string honouring the SMB Unicode rules: when unicode is set the cursor first skips one pad byte if the current position is odd relative to base, then decodes UTF-16LE up to and including the 16-bit terminator.

base must be the absolute frame offset of buf[0].

Source

pub fn fixed_string(&mut self, len: usize, unicode: bool) -> String

Read exactly len bytes as a lossy UTF-16LE or OEM string (no terminator handling) — used for length-prefixed name fields.

Trait Implementations§

Source§

impl<'a> Debug for Reader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

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.