pub struct TLVSequence<'a>(/* private fields */);Expand description
A newtype for iterating over the TLVElement “child” instances contained in TLVElement which is a TLV container
(array, struct or list).
(Internally, TLVSequence might be used for other purposes, but the external contract is only the one from above.)
Just like TLVElement, TLVSequence is a newtype over a byte slice - the byte sub-slice of the parent TLVElement
container where its value starts.
Unlike TLVElement, TLVSequence - as the name suggests - represents a sequence of 0, 1 or more TLVElements.
The only public API of TLVSequence however is the iter method which returns a TLVContainerIter iterator over
the TLVElement instances in the sequence.
Implementations§
Source§impl<'a> TLVSequence<'a>
impl<'a> TLVSequence<'a>
Sourcepub fn iter(&self) -> TLVSequenceIter<'a> ⓘ
pub fn iter(&self) -> TLVSequenceIter<'a> ⓘ
Return an iterator over the TLVElement instances in this TLVSequence.
Sourcepub fn tlv_iter(&self) -> TLVSequenceTLVIter<'a> ⓘ
pub fn tlv_iter(&self) -> TLVSequenceTLVIter<'a> ⓘ
Return an iterator over the TLV instances in this TLVSequence.
The difference with iter is that for container elements, tlv_iter
will return separate TLV instances for the container start, the container
elements and the container end, where if an element in the container is
itself a container, the algorithm will be applied recursively to the inner container.
Sourcepub fn ctx(&self, ctx: u8) -> Result<TLVElement<'a>, Error>
pub fn ctx(&self, ctx: u8) -> Result<TLVElement<'a>, Error>
A convenience utility that returns the first TLVElement in the sequence
which is tagged with a context tag (TLVTag::Context) where the context ID
is matching the ID passed in the ctx parameter.
If there is no TLV element tagged with a context tag with the matching ID, the method will return an error.
Sourcepub fn find_ctx(&self, ctx: u8) -> Result<TLVElement<'a>, Error>
pub fn find_ctx(&self, ctx: u8) -> Result<TLVElement<'a>, Error>
A convenience utility that returns the first TLVElement in the sequence
which is tagged with a context tag (TLVTag::Context) where the context ID
is matching the ID passed in the ctx parameter.
If there is no TLV element tagged with a context tag with the matching ID, the method
will return an empty TLVElement.
Sourcepub fn scan_ctx(&mut self, ctx: u8) -> Result<TLVElement<'a>, Error>
pub fn scan_ctx(&mut self, ctx: u8) -> Result<TLVElement<'a>, Error>
A convenience utility that returns the first TLVElement in the sequence
which is tagged with a context tag (TLVTag::Context) where the context ID
is equal to the ID passed in the ctx parameter.
If there is no TLV element tagged with a context tag with the matching ID, the method will return an empty TLV element.
As a side effect of calling this method, the TLVSequence instance will be updated
to point to the next element after the found element, or if an element with the
provided context ID does not exist, to the first element with a bigger context ID than
the one we are looking for.
Sourcepub fn scan_map<F, T>(&mut self, f: F) -> Result<T, Error>
pub fn scan_map<F, T>(&mut self, f: F) -> Result<T, Error>
A convenience utility that returns scans the elements in the sequence,
in-order and stops scanning once the provided mapping closure f
returns a non-empty result.
As a side effect of calling this method, the TLVSequence instance will be updated
to point to the next element after the one on which the provided closure
returned a non-empty result.
Note that the closure must ultimately return a non-empty result - if for nothing else then for the empty element that is passed to it when the sequence is exhausted, or else the method would loop forever.
Sourcepub fn raw_value(&self) -> Result<&'a [u8], Error>
pub fn raw_value(&self) -> Result<&'a [u8], Error>
Return a raw byte sub-slice representing the TLV-encoded elements and only those
elements that belong to the TLV container whose elements are represented by this TLVSequence instance.
This method is necessary, because both TLVElement instances, as well as TLVSequence instances - for optimization purposes -
might be constructed during iteration on slices which are technically longer than the actual TLV-encoded data
they represent.
So in case the user is need of the actual, exact raw representation of a TLV container value, this method is provided.
Trait Implementations§
Source§impl<'a> Clone for TLVSequence<'a>
impl<'a> Clone for TLVSequence<'a>
Source§fn clone(&self) -> TLVSequence<'a>
fn clone(&self) -> TLVSequence<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TLVSequence<'_>
impl Debug for TLVSequence<'_>
Source§impl Display for TLVSequence<'_>
impl Display for TLVSequence<'_>
impl<'a> Eq for TLVSequence<'a>
Source§impl<'a> Hash for TLVSequence<'a>
impl<'a> Hash for TLVSequence<'a>
Source§impl<'a> PartialEq for TLVSequence<'a>
impl<'a> PartialEq for TLVSequence<'a>
impl<'a> StructuralPartialEq for TLVSequence<'a>
Auto Trait Implementations§
impl<'a> Freeze for TLVSequence<'a>
impl<'a> RefUnwindSafe for TLVSequence<'a>
impl<'a> Send for TLVSequence<'a>
impl<'a> Sync for TLVSequence<'a>
impl<'a> Unpin for TLVSequence<'a>
impl<'a> UnsafeUnpin for TLVSequence<'a>
impl<'a> UnwindSafe for TLVSequence<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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