Struct bcder::decode::LimitedSource
source · [−]pub struct LimitedSource<S> { /* private fields */ }
Expand description
A source that can be limited to a certain number of octets.
This type wraps another source and allows access to be limited to a certain number of octets. It will never provide access to more than that number of octets. Any attempt to advance over more octets will fail with a malformed error.
The limit is, however, independent of the underlying source. It can be larger than the number of octets actually available in the source.
The limit can be changed or even removed at any time.
Implementations
sourceimpl<S> LimitedSource<S>
impl<S> LimitedSource<S>
sourcepub fn new(source: S) -> Self
pub fn new(source: S) -> Self
Creates a new limited source for the given source.
The return limited source will have no limit just yet.
sourcepub fn limit(&self) -> Option<usize>
pub fn limit(&self) -> Option<usize>
Returns the current limit.
Returns None
if there is no limit. Otherwise, the number returned
is the number of remaining octets before the limit is reached. This
does not necessarily mean that that many octets are actually
available in the underlying source.
sourcepub fn limit_further(&mut self, limit: Option<usize>) -> Option<usize>
pub fn limit_further(&mut self, limit: Option<usize>) -> Option<usize>
Sets a more strict limit.
The method will panic (!) if you are trying to set a new limit that
is larger than the current limit or if you are trying to remove
the limit by passing None
if there currently is a limit set.
Returns the old limit.
sourceimpl<S: Source> LimitedSource<S>
impl<S: Source> LimitedSource<S>
sourcepub fn skip_all(&mut self) -> Result<(), DecodeError<S::Error>>
pub fn skip_all(&mut self) -> Result<(), DecodeError<S::Error>>
Skip over all remaining octets until the current limit is reached.
If there currently is no limit, the method will panic. Otherwise it will simply advance to the end of the limit which may be something the underlying source doesn’t like and thus produce an error.
sourcepub fn take_all(&mut self) -> Result<Bytes, DecodeError<S::Error>>
pub fn take_all(&mut self) -> Result<Bytes, DecodeError<S::Error>>
Returns a bytes value containing all octets until the current limit.
If there currently is no limit, the method will panic. Otherwise it tries to acquire a bytes value for the octets from the current position to the end of the limit and advance to the end of the limit.
This will result in a source error if the underlying source returns an error. It will result in a content error if the underlying source ends before the limit is reached.
sourcepub fn exhausted(&mut self) -> Result<(), DecodeError<S::Error>>
pub fn exhausted(&mut self) -> Result<(), DecodeError<S::Error>>
Checks whether the end of the limit has been reached.
If a limit is currently set, the method will return a malformed error if it is larger than zero, i.e., if there are octets left to advance over before reaching the limit.
If there is no limit set, the method will try to access one single octet and return a malformed error if that is actually possible, i.e., if there are octets left in the underlying source.
Any source errors are passed through. If there the data is not exhausted as described above, a content error is created.
Trait Implementations
sourceimpl<S: Clone> Clone for LimitedSource<S>
impl<S: Clone> Clone for LimitedSource<S>
sourcefn clone(&self) -> LimitedSource<S>
fn clone(&self) -> LimitedSource<S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<S: Debug> Debug for LimitedSource<S>
impl<S: Debug> Debug for LimitedSource<S>
sourceimpl<S: Source> Source for LimitedSource<S>
impl<S: Source> Source for LimitedSource<S>
sourcefn request(&mut self, len: usize) -> Result<usize, Self::Error>
fn request(&mut self, len: usize) -> Result<usize, Self::Error>
Request at least len
bytes to be available. Read more
sourcefn slice(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
fn slice(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Returns a bytes slice with the available data. Read more
sourcefn bytes(&self, start: usize, end: usize) -> Bytes
fn bytes(&self, start: usize, end: usize) -> Bytes
Produces a Bytes
value from part of the data. Read more
sourcefn skip(&mut self, len: usize) -> Result<usize, Self::Error>
fn skip(&mut self, len: usize) -> Result<usize, Self::Error>
Skip over the next len
bytes. Read more
sourcefn take_u8(&mut self) -> Result<u8, DecodeError<Self::Error>>
fn take_u8(&mut self) -> Result<u8, DecodeError<Self::Error>>
Takes a single octet from the source. Read more
sourcefn take_opt_u8(&mut self) -> Result<Option<u8>, Self::Error>
fn take_opt_u8(&mut self) -> Result<Option<u8>, Self::Error>
Takes an optional octet from the source. Read more
sourcefn content_err(&self, err: impl Into<ContentError>) -> DecodeError<Self::Error>
fn content_err(&self, err: impl Into<ContentError>) -> DecodeError<Self::Error>
Returns a content error at the current position of the source.
Auto Trait Implementations
impl<S> RefUnwindSafe for LimitedSource<S> where
S: RefUnwindSafe,
impl<S> Send for LimitedSource<S> where
S: Send,
impl<S> Sync for LimitedSource<S> where
S: Sync,
impl<S> Unpin for LimitedSource<S> where
S: Unpin,
impl<S> UnwindSafe for LimitedSource<S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more