Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<W, A, const PAD: bool>
where A: Alphabet,
{ /* private fields */ }
Expand description

A streaming Base64 decoder for std::io::Write.

Like any Write implementation, Write::write may accept only part of the provided input. Accepted input may be held as decoded output until Write::flush, Self::try_finish, Self::finish, or a later write drains the wrapped writer. Use Write::write_all when the whole input slice must be consumed.

Implementations§

Source§

impl<W, A, const PAD: bool> Decoder<W, A, PAD>
where A: Alphabet,

Source

pub const fn new(inner: W, engine: Engine<A, PAD>) -> Self

Creates a new streaming decoder.

Source

pub fn get_ref(&self) -> &W

Returns a shared reference to the wrapped writer.

Source

pub fn get_mut(&mut self) -> &mut W

Returns a mutable reference to the wrapped writer.

Source

pub const fn engine(&self) -> Engine<A, PAD>

Returns the Base64 engine used by this adapter.

Source

pub const fn is_padded(&self) -> bool

Returns whether this adapter uses padded Base64.

Source

pub const fn pending_len(&self) -> usize

Returns the number of encoded input bytes currently buffered until a complete 4-byte Base64 decode quantum is available.

Source

pub const fn has_pending_input(&self) -> bool

Returns whether this decoder currently holds a partial input quantum.

Source

pub const fn pending_input_needed_len(&self) -> usize

Returns how many additional input bytes are needed to complete the currently buffered decode quantum.

Returns 0 when no partial input quantum is buffered.

Source

pub const fn buffered_output_len(&self) -> usize

Returns the number of decoded bytes buffered for the wrapped writer after a previous write or flush could not fully drain them.

Source

pub const fn buffered_output_capacity(&self) -> usize

Returns the maximum number of decoded bytes this adapter can buffer before returning bytes to the caller.

Source

pub const fn buffered_output_remaining_capacity(&self) -> usize

Returns how many more decoded bytes can be buffered before this adapter must drain the wrapped writer.

Source

pub const fn has_buffered_output(&self) -> bool

Returns whether this decoder has decoded output waiting to be written to the wrapped writer.

Source

pub const fn has_terminal_padding(&self) -> bool

Returns whether this decoder has processed a terminal padded block.

Once this returns true, later calls to Write::write with additional input return an error because strict Base64 does not permit trailing payload bytes after padding.

Source

pub const fn is_finalized(&self) -> bool

Returns whether this decoder has been finalized.

Once this returns true, later non-empty writes return an error.

Source

pub const fn is_failed(&self) -> bool

Returns whether this decoder has rejected malformed Base64 input.

Once this returns true, later writes, flushes, and finalization attempts return an error. The unchecked Self::into_inner method can still be used for explicit recovery of the wrapped writer.

Source

pub const fn can_into_inner(&self) -> bool

Returns whether Self::try_into_inner can recover the wrapped writer without discarding pending encoded input.

Source

pub fn into_inner(self) -> W

Consumes the decoder without flushing pending input.

Prefer Self::finish when the decoded output must be complete.

Source

pub fn try_into_inner(self) -> Result<W, Self>

Consumes the decoder only when no partial input quantum is buffered.

This does not flush or finalize the wrapped writer. It is a checked alternative to Self::into_inner for callers that want to avoid accidentally discarding pending encoded input bytes.

Source§

impl<W, A, const PAD: bool> Decoder<W, A, PAD>
where W: Write, A: Alphabet,

Source

pub fn try_finish(&mut self) -> Result<()>

Validates any final pending input and flushes the wrapped writer without consuming this decoder.

After this succeeds, Self::pending_len returns 0, later writes are rejected, and Self::finish can still be used to recover the wrapped writer. If the final buffered input is malformed, an error is returned and the caller still owns the decoder for diagnostics or explicit recovery.

Source

pub fn finish(self) -> Result<W>

Validates final pending input, flushes the wrapped writer, and returns it.

Trait Implementations§

Source§

impl<W, A, const PAD: bool> Debug for Decoder<W, A, PAD>
where A: Alphabet,

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<W, A, const PAD: bool> Drop for Decoder<W, A, PAD>
where A: Alphabet,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<W, A, const PAD: bool> Write for Decoder<W, A, PAD>
where W: Write, A: Alphabet,

Source§

fn write(&mut self, input: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<W, A, const PAD: bool> Freeze for Decoder<W, A, PAD>
where W: Freeze,

§

impl<W, A, const PAD: bool> RefUnwindSafe for Decoder<W, A, PAD>

§

impl<W, A, const PAD: bool> Send for Decoder<W, A, PAD>
where W: Send, A: Send,

§

impl<W, A, const PAD: bool> Sync for Decoder<W, A, PAD>
where W: Sync, A: Sync,

§

impl<W, A, const PAD: bool> Unpin for Decoder<W, A, PAD>
where W: Unpin, A: Unpin,

§

impl<W, A, const PAD: bool> UnsafeUnpin for Decoder<W, A, PAD>
where W: UnsafeUnpin,

§

impl<W, A, const PAD: bool> UnwindSafe for Decoder<W, A, PAD>
where W: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.