[−][src]Struct bcder::Captured
A wrapper for BER encoded data.
This types keeps a sequence of BER-encoded data in a Bytes
value. It
allows for delayed processing of this data and therefore zero-allocation
handling of sequences and similar types by implementing iterators and
helper types that work directly on the the still-encoded data.
You usually acquire a value of this type trough the capture
family of
methods on constructed BER content. Alternatively, you can also construct
a new value using regular encoding via the from_values
function or
incrementally by starting with empty
and then adding more content
with [extent
].
Once you have a captured value, you can use the decode
method to
decode the entire captured value or decode_partial
to decode some
values at the start of the captured value. The latter manipulates the
captured content by moving past the captured values and is therefore
perfect for an iterator.
The value also remembers what Mode
the original data was decoded in
and will automatically use this encoding in those methods.
Methods
impl Captured
[src]
pub fn from_values<V: Values>(mode: Mode, values: V) -> Self
[src]
Creates a captured value by encoding data.
The function takes a value encoder, encodes it into a bytes value with the given mode, and returns the resulting data as a captured value.
pub fn empty(mode: Mode) -> Self
[src]
Creates a new empty captured value in the given mode.
pub fn extend<V: Values>(&mut self, values: V)
[src]
Extends the captured value by encoding the given values.
The function encodes the given values in the captured value’s own mode and places the encoded content at the end of the captured value.
pub fn decode<F, T>(self, op: F) -> Result<T, Error> where
F: FnOnce(&mut Constructed<Bytes>) -> Result<T, Error>,
[src]
F: FnOnce(&mut Constructed<Bytes>) -> Result<T, Error>,
Decodes the full content using the provided function argument.
The method consumes the value. If you want to keep it around, simply clone it first. Since bytes values are cheap to clone, this is relatively cheap.
pub fn decode_partial<F, T>(&mut self, op: F) -> Result<T, Error> where
F: FnOnce(&mut Constructed<&mut Bytes>) -> Result<T, Error>,
[src]
F: FnOnce(&mut Constructed<&mut Bytes>) -> Result<T, Error>,
Decodes the beginning of the content of the captured value.
The method calls op
to parse a number of values from the beginning
of the value and then advances the content of the captured value until
after the end of these decoded values.
pub fn into_bytes(self) -> Bytes
[src]
Trades the value for a bytes value with the raw data.
pub fn as_slice(&self) -> &[u8]
[src]
Returns a bytes slice with the raw data of the captured value.
Methods from Deref<Target = Bytes>
pub fn len(&self) -> usize
[src]
Returns the number of bytes contained in this Bytes
.
Examples
use bytes::Bytes; let b = Bytes::from(&b"hello"[..]); assert_eq!(b.len(), 5);
pub fn is_empty(&self) -> bool
[src]
Returns true if the Bytes
has a length of 0.
Examples
use bytes::Bytes; let b = Bytes::new(); assert!(b.is_empty());
pub fn slice(&self, begin: usize, end: usize) -> Bytes
[src]
Returns a slice of self for the index range [begin..end)
.
This will increment the reference count for the underlying memory and
return a new Bytes
handle set to the slice.
This operation is O(1)
.
Examples
use bytes::Bytes; let a = Bytes::from(&b"hello world"[..]); let b = a.slice(2, 5); assert_eq!(&b[..], b"llo");
Panics
Requires that begin <= end
and end <= self.len()
, otherwise slicing
will panic.
pub fn slice_from(&self, begin: usize) -> Bytes
[src]
Returns a slice of self for the index range [begin..self.len())
.
This will increment the reference count for the underlying memory and
return a new Bytes
handle set to the slice.
This operation is O(1)
and is equivalent to self.slice(begin, self.len())
.
Examples
use bytes::Bytes; let a = Bytes::from(&b"hello world"[..]); let b = a.slice_from(6); assert_eq!(&b[..], b"world");
Panics
Requires that begin <= self.len()
, otherwise slicing will panic.
pub fn slice_to(&self, end: usize) -> Bytes
[src]
Returns a slice of self for the index range [0..end)
.
This will increment the reference count for the underlying memory and
return a new Bytes
handle set to the slice.
This operation is O(1)
and is equivalent to self.slice(0, end)
.
Examples
use bytes::Bytes; let a = Bytes::from(&b"hello world"[..]); let b = a.slice_to(5); assert_eq!(&b[..], b"hello");
Panics
Requires that end <= self.len()
, otherwise slicing will panic.
pub fn slice_ref(&self, subset: &[u8]) -> Bytes
[src]
Returns a slice of self that is equivalent to the given subset
.
When processing a Bytes
buffer with other tools, one often gets a
&[u8]
which is in fact a slice of the Bytes
, i.e. a subset of it.
This function turns that &[u8]
into another Bytes
, as if one had
called self.slice()
with the offsets that correspond to subset
.
This operation is O(1)
.
Examples
use bytes::Bytes; let bytes = Bytes::from(&b"012345678"[..]); let as_slice = bytes.as_ref(); let subset = &as_slice[2..6]; let subslice = bytes.slice_ref(&subset); assert_eq!(&subslice[..], b"2345");
Panics
Requires that the given sub
slice is in fact contained within the
Bytes
buffer; otherwise this function will panic.
Trait Implementations
impl AsRef<[u8]> for Captured
[src]
impl AsRef<Bytes> for Captured
[src]
impl Clone for Captured
[src]
impl Debug for Captured
[src]
impl Deref for Captured
[src]
impl Values for Captured
[src]
Auto Trait Implementations
impl RefUnwindSafe for Captured
impl Send for Captured
impl Sync for Captured
impl Unpin for Captured
impl UnwindSafe for Captured
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,