pub struct Decoder<'i, E: Encoding> { /* private fields */ }
Expand description
Stateful Base64 decoder with support for buffered, incremental decoding.
The E
type parameter can be any type which impls Encoding
such as
Base64
or Base64Unpadded
.
Implementations§
source§impl<'i, E: Encoding> Decoder<'i, E>
impl<'i, E: Encoding> Decoder<'i, E>
sourcepub fn new(input: &'i [u8]) -> Result<Self, Error>
pub fn new(input: &'i [u8]) -> Result<Self, Error>
Create a new decoder for a byte slice containing contiguous (non-newline-delimited) Base64-encoded data.
§Returns
Ok(decoder)
on success.Err(Error::InvalidLength)
if the input buffer is empty.
sourcepub fn new_wrapped(input: &'i [u8], line_width: usize) -> Result<Self, Error>
pub fn new_wrapped(input: &'i [u8], line_width: usize) -> Result<Self, Error>
Create a new decoder for a byte slice containing Base64 which line wraps at the given line length.
Trailing newlines are not supported and must be removed in advance.
Newlines are handled according to what are roughly RFC7468 conventions:
[parsers] MUST handle different newline conventions
RFC7468 allows any of the following as newlines, and allows a mixture of different types of newlines:
eol = CRLF / CR / LF
§Returns
Ok(decoder)
on success.Err(Error::InvalidLength)
if the input buffer is empty or the line width is zero.
sourcepub fn decode<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
pub fn decode<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
Fill the provided buffer with data decoded from Base64.
Enough Base64 input data must remain to fill the entire buffer.
§Returns
Ok(bytes)
if the expected amount of data was readErr(Error::InvalidLength)
if the exact amount of data couldn’t be read
sourcepub fn decode_to_end<'o>(
&mut self,
buf: &'o mut Vec<u8>,
) -> Result<&'o [u8], Error>
pub fn decode_to_end<'o>( &mut self, buf: &'o mut Vec<u8>, ) -> Result<&'o [u8], Error>
Decode all remaining Base64 data, placing the result into buf
.
If successful, this function will return the total number of bytes
decoded into buf
.
sourcepub fn remaining_len(&self) -> usize
pub fn remaining_len(&self) -> usize
Get the length of the remaining data after Base64 decoding.
Decreases every time data is decoded.
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Has all of the input data been decoded?
Trait Implementations§
source§impl<'i, E: Encoding> Read for Decoder<'i, E>
impl<'i, E: Encoding> Read for Decoder<'i, E>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreAuto Trait Implementations§
impl<'i, E> Freeze for Decoder<'i, E>
impl<'i, E> RefUnwindSafe for Decoder<'i, E>where
E: RefUnwindSafe,
impl<'i, E> Send for Decoder<'i, E>
impl<'i, E> Sync for Decoder<'i, E>
impl<'i, E> Unpin for Decoder<'i, E>where
E: Unpin,
impl<'i, E> UnwindSafe for Decoder<'i, E>where
E: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)