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§
source§impl<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.
source§impl<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§
source§impl<S: Clone> Clone for LimitedSource<S>
impl<S: Clone> Clone for LimitedSource<S>
source§fn clone(&self) -> LimitedSource<S>
fn clone(&self) -> LimitedSource<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S: Debug> Debug for LimitedSource<S>
impl<S: Debug> Debug for LimitedSource<S>
source§impl<S: Source> Source for LimitedSource<S>
impl<S: Source> Source for LimitedSource<S>
source§fn request(&mut self, len: usize) -> Result<usize, Self::Error>
fn request(&mut self, len: usize) -> Result<usize, Self::Error>
len
bytes to be available. Read moresource§fn bytes(&self, start: usize, end: usize) -> Bytes
fn bytes(&self, start: usize, end: usize) -> Bytes
Bytes
value from part of the data. Read moresource§fn skip(&mut self, len: usize) -> Result<usize, Self::Error>
fn skip(&mut self, len: usize) -> Result<usize, Self::Error>
len
bytes. Read more