Struct bcder::captured::Captured[][src]

pub struct Captured { /* fields omitted */ }
Expand description

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 via the CapturedBuilder.

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.

Implementations

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.

Creates a new empty captured value in the given mode.

Creates a builder for a captured value in the given mode.

Converts the captured values into a builder in order to add new values.

Because the captured values might be shared, this requires copying the underlying data.

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.

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.

Trades the value for a bytes value with the raw data.

Returns a bytes slice with the raw data of the captured value.

Methods from Deref<Target = Bytes>

Returns the number of bytes contained in this Bytes.

Examples
use bytes::Bytes;

let b = Bytes::from(&b"hello"[..]);
assert_eq!(b.len(), 5);

Returns true if the Bytes has a length of 0.

Examples
use bytes::Bytes;

let b = Bytes::new();
assert!(b.is_empty());

Returns a slice of self for the provided range.

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.

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

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Returns the length of the encoded values for the given mode.

Encodes the values in the given mode and writes them to target.

Converts the encoder into one with an explicit tag.

Captures the encoded values in the given mode.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.