Decoder

Struct Decoder 

Source
pub struct Decoder { /* private fields */ }
Expand description

BER decoder that reads from a byte buffer.

Implementations§

Source§

impl Decoder

Source

pub fn new(data: Bytes) -> Self

Create a new decoder from bytes.

Source

pub fn from_slice(data: &[u8]) -> Self

Create a decoder from a byte slice (copies the data).

Source

pub fn offset(&self) -> usize

Get the current offset.

Source

pub fn remaining(&self) -> usize

Get remaining bytes.

Source

pub fn is_empty(&self) -> bool

Check if we’ve reached the end.

Source

pub fn peek_byte(&self) -> Option<u8>

Peek at the next byte without consuming it.

Source

pub fn peek_tag(&self) -> Option<u8>

Peek at the next tag without consuming it.

Source

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

Read a single byte.

Source

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

Read a tag byte.

Source

pub fn read_length(&mut self) -> Result<usize>

Read a length and return (length, bytes consumed).

Source

pub fn read_bytes(&mut self, len: usize) -> Result<Bytes>

Read raw bytes without copying.

Source

pub fn expect_tag(&mut self, expected: u8) -> Result<usize>

Read and expect a specific tag, returning the content length.

Source

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

Read a BER integer (signed).

Source

pub fn read_integer_value(&mut self, len: usize) -> Result<i32>

Read integer value given the length.

Source

pub fn read_integer64(&mut self, expected_tag: u8) -> Result<u64>

Read a 64-bit unsigned integer (Counter64).

Source

pub fn read_integer64_value(&mut self, len: usize) -> Result<u64>

Read 64-bit unsigned integer value given the length.

Source

pub fn read_unsigned32(&mut self, expected_tag: u8) -> Result<u32>

Read an unsigned 32-bit integer with specific tag.

Source

pub fn read_unsigned32_value(&mut self, len: usize) -> Result<u32>

Read unsigned 32-bit integer value given length.

Source

pub fn read_octet_string(&mut self) -> Result<Bytes>

Read an OCTET STRING.

Source

pub fn read_null(&mut self) -> Result<()>

Read a NULL.

Source

pub fn read_oid(&mut self) -> Result<Oid>

Read an OBJECT IDENTIFIER.

Source

pub fn read_oid_value(&mut self, len: usize) -> Result<Oid>

Read an OID given a pre-read length.

Source

pub fn read_sequence(&mut self) -> Result<Decoder>

Read a SEQUENCE, returning a decoder for its contents.

Source

pub fn read_constructed(&mut self, expected_tag: u8) -> Result<Decoder>

Read a constructed type with a specific tag, returning a decoder for its contents.

Source

pub fn read_ip_address(&mut self) -> Result<[u8; 4]>

Read an IP address.

Source

pub fn skip_tlv(&mut self) -> Result<()>

Skip a TLV (tag-length-value) without parsing.

Source

pub fn sub_decoder(&mut self, len: usize) -> Result<Decoder>

Create a sub-decoder for a portion of the remaining data.

Source

pub fn as_bytes(&self) -> &Bytes

Get the underlying bytes for the entire buffer.

Source

pub fn remaining_slice(&self) -> &[u8]

Get remaining data as a slice.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more