pub struct Decoder { /* private fields */ }Expand description
BER decoder that reads from a byte buffer.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn with_target(data: Bytes, target: SocketAddr) -> Self
pub fn with_target(data: Bytes, target: SocketAddr) -> Self
Create a decoder from bytes with a target address for error context.
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Create a decoder from a byte slice (copies the data).
Sourcepub fn peek_tag(&self) -> Option<u8>
pub fn peek_tag(&self) -> Option<u8>
Peek at the next tag without consuming it.
Returns None if the buffer is empty or if the next byte signals a
multi-byte tag (low five bits all set, i.e. byte & 0x1F == 0x1F).
Valid SNMP uses only single-byte tags (all defined tags are below 31).
Sourcepub fn read_tag(&mut self) -> Result<u8>
pub fn read_tag(&mut self) -> Result<u8>
Read a tag byte.
Returns an error if the tag byte signals a multi-byte tag
(low five bits all set, i.e. byte & 0x1F == 0x1F).
Valid SNMP uses only single-byte tags (all defined tags are below 31).
Sourcepub fn read_length(&mut self) -> Result<usize>
pub fn read_length(&mut self) -> Result<usize>
Read a length and return (length, bytes consumed).
Sourcepub fn read_bytes(&mut self, len: usize) -> Result<Bytes>
pub fn read_bytes(&mut self, len: usize) -> Result<Bytes>
Read raw bytes without copying.
Sourcepub fn expect_tag(&mut self, expected: u8) -> Result<usize>
pub fn expect_tag(&mut self, expected: u8) -> Result<usize>
Read and expect a specific tag, returning the content length.
Sourcepub fn read_integer(&mut self) -> Result<i32>
pub fn read_integer(&mut self) -> Result<i32>
Read a BER integer (signed).
Sourcepub fn read_integer_value(&mut self, len: usize) -> Result<i32>
pub fn read_integer_value(&mut self, len: usize) -> Result<i32>
Read integer value given the length.
Sourcepub fn read_integer64(&mut self, expected_tag: u8) -> Result<u64>
pub fn read_integer64(&mut self, expected_tag: u8) -> Result<u64>
Read a 64-bit unsigned integer (Counter64).
Sourcepub fn read_integer64_value(&mut self, len: usize) -> Result<u64>
pub fn read_integer64_value(&mut self, len: usize) -> Result<u64>
Read 64-bit unsigned integer value given the length.
Sourcepub fn read_unsigned32(&mut self, expected_tag: u8) -> Result<u32>
pub fn read_unsigned32(&mut self, expected_tag: u8) -> Result<u32>
Read an unsigned 32-bit integer with specific tag.
Sourcepub fn read_unsigned32_value(&mut self, len: usize) -> Result<u32>
pub fn read_unsigned32_value(&mut self, len: usize) -> Result<u32>
Read unsigned 32-bit integer value given length.
Sourcepub fn read_octet_string(&mut self) -> Result<Bytes>
pub fn read_octet_string(&mut self) -> Result<Bytes>
Read an OCTET STRING.
Sourcepub fn read_oid_value(&mut self, len: usize) -> Result<Oid>
pub fn read_oid_value(&mut self, len: usize) -> Result<Oid>
Read an OID given a pre-read length.
Sourcepub fn read_sequence(&mut self) -> Result<Decoder>
pub fn read_sequence(&mut self) -> Result<Decoder>
Read a SEQUENCE, returning a decoder for its contents.
Sourcepub fn read_constructed(&mut self, expected_tag: u8) -> Result<Decoder>
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.
Sourcepub fn read_ip_address(&mut self) -> Result<[u8; 4]>
pub fn read_ip_address(&mut self) -> Result<[u8; 4]>
Read an IP address.
Sourcepub fn sub_decoder(&mut self, len: usize) -> Result<Decoder>
pub fn sub_decoder(&mut self, len: usize) -> Result<Decoder>
Create a sub-decoder for a portion of the remaining data.
Sourcepub fn remaining_slice(&self) -> &[u8] ⓘ
pub fn remaining_slice(&self) -> &[u8] ⓘ
Get remaining data as a slice.
Auto Trait Implementations§
impl !Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnsafeUnpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more