Skip to main content

FieldDecoder

Struct FieldDecoder 

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

A sequential field decoder that reads typed values from a byte buffer.

Each read_* method advances an internal offset. The methods return PersistError::SerializationError if there are not enough bytes remaining.

Implementations§

Source§

impl<'a> FieldDecoder<'a>

Source

pub fn new(data: &'a [u8]) -> Self

Creates a new decoder positioned at the start of data.

Source

pub fn position(&self) -> usize

Returns the current byte offset within the buffer.

Source

pub fn remaining(&self) -> usize

Returns the number of bytes remaining to be read.

Source

pub fn is_exhausted(&self) -> bool

Returns true if all bytes have been consumed.

Source

pub fn read_u8(&mut self) -> Result<u8>

Reads a u8.

Source

pub fn read_u16(&mut self) -> Result<u16>

Reads a u16 in big-endian byte order.

Source

pub fn read_u32(&mut self) -> Result<u32>

Reads a u32 in big-endian byte order.

Source

pub fn read_u64(&mut self) -> Result<u64>

Reads a u64 in big-endian byte order.

Source

pub fn read_i8(&mut self) -> Result<i8>

Reads an i8.

Source

pub fn read_i16(&mut self) -> Result<i16>

Reads an i16 in big-endian byte order.

Source

pub fn read_i32(&mut self) -> Result<i32>

Reads an i32 in big-endian byte order.

Source

pub fn read_i64(&mut self) -> Result<i64>

Reads an i64 in big-endian byte order.

Source

pub fn read_f32(&mut self) -> Result<f32>

Reads an f32 in big-endian byte order.

Source

pub fn read_f64(&mut self) -> Result<f64>

Reads an f64 in big-endian byte order.

Source

pub fn read_bool(&mut self) -> Result<bool>

Reads a bool encoded as a single byte.

Source

pub fn read_string(&mut self) -> Result<String>

Reads a length-prefixed UTF-8 string.

Source

pub fn read_bytes(&mut self) -> Result<Vec<u8>>

Reads a length-prefixed byte slice.

Source

pub fn read_option_string(&mut self) -> Result<Option<String>>

Reads an optional string (bool tag + optional value).

Source

pub fn read_option_u64(&mut self) -> Result<Option<u64>>

Reads an optional u64 (bool tag + optional value).

Auto Trait Implementations§

§

impl<'a> Freeze for FieldDecoder<'a>

§

impl<'a> RefUnwindSafe for FieldDecoder<'a>

§

impl<'a> Send for FieldDecoder<'a>

§

impl<'a> Sync for FieldDecoder<'a>

§

impl<'a> Unpin for FieldDecoder<'a>

§

impl<'a> UnsafeUnpin for FieldDecoder<'a>

§

impl<'a> UnwindSafe for FieldDecoder<'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.