Decoder

Struct Decoder 

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

Binary TLV decoder.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

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

Creates a new decoder from a byte slice.

Source

pub fn position(&self) -> usize

Returns the current position.

Source

pub fn is_done(&self) -> bool

Returns true if all data has been consumed.

Source

pub fn remaining(&self) -> usize

Returns remaining bytes.

Source

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

Decodes a tagged u64.

§Errors

Returns error if tag mismatch or malformed varint.

Source

pub fn bytes(&mut self) -> Result<&'a [u8], BinaryCodecError>

Decodes tagged bytes.

§Errors
  • BinaryCodecError::Tag if tag mismatch
  • BinaryCodecError::SizeLimit if length exceeds MAX_BYTES_LEN
  • BinaryCodecError::Eof if insufficient data
Source

pub fn str(&mut self) -> Result<&'a str, BinaryCodecError>

Decodes a tagged UTF-8 string.

§Errors
  • BinaryCodecError::Tag if tag mismatch
  • BinaryCodecError::SizeLimit if length exceeds MAX_BYTES_LEN
  • BinaryCodecError::Eof if insufficient data
  • BinaryCodecError::Utf8 if invalid UTF-8
Source

pub fn cid32(&mut self) -> Result<Cid32, BinaryCodecError>

Decodes a 32-byte CID.

§Errors

Returns error if tag mismatch or insufficient data.

Source

pub fn public_key(&mut self) -> Result<PublicKeyBytes, BinaryCodecError>

Decodes a 32-byte public key.

§Errors

Returns error if tag mismatch or insufficient data.

Source

pub fn signature(&mut self) -> Result<SignatureBytes, BinaryCodecError>

Decodes a 64-byte signature.

§Errors

Returns error if tag mismatch or insufficient data.

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'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> Same for T

Source§

type Output = T

Should always be Self
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.