Skip to main content

Base64Decoder

Struct Base64Decoder 

Source
pub struct Base64Decoder { /* private fields */ }
Expand description

Decodes Base64 incrementally using a strict configuration.

The decoder uses fixed-size state and does not allocate. Call reset before streaming. Incomplete non-EOF input remains caller-owned and must be supplied again with additional input or to transcode_eof. Complete describes the currently visible input and does not establish source EOF; call transcode_eof only after the source confirms EOF. A domain error may occur after earlier bytes in the same operation were written, and poisons the decoder; call reset before reusing it. If output capacity is insufficient, use the returned progress to retry with unconsumed input and a larger output buffer. NeedOutput.required is the minimum total capacity from the advanced output position (output_index + progress.written()) for the next step. When retaining the output buffer, its length must cover that position plus required; when switching to an empty buffer at index zero, provide at least required slots.

The outer transcoder error reports a position in the input slice passed to the current call. Its MiscCodecError and base64::DecodeError source keep the engine sub-slice position, which can vary with batching, EOF handling, and output capacity. Errors without an exact engine position use the failing segment’s start in the outer error. These positions are not cumulative stream offsets.

§Examples

use qubit_codec::TranscodeStatus;
use qubit_codec::Transcoder;
use qubit_codec_misc::Base64Decoder;

let mut decoder = Base64Decoder::standard();
let mut output = [0; 3];
decoder.reset(&mut output, 0).unwrap();
let progress = decoder.transcode(b"TQ", 0, &mut output, 0).unwrap();
assert_eq!(progress.read(), 0);
assert!(matches!(progress.status(), TranscodeStatus::NeedInput { .. }));
// Keep the unconsumed TQ, append ==, and confirm EOF with the source.
let progress = decoder.transcode_eof(b"TQ==", 0, &mut output, 0).unwrap();
assert_eq!(progress.read(), 4);
assert_eq!(&output[..progress.written()], b"M");
assert_eq!(decoder.finish(&mut [], 0).unwrap(), 0);

Implementations§

Source§

impl Base64Decoder

Source

pub fn standard() -> Self

Creates a strict standard Base64 decoder with padding.

The decoder requires reset before streaming and does not allocate.

§Returns

Returns an uninitialized decoder using the standard alphabet and required padding.

Source

pub fn standard_no_pad() -> Self

Creates a strict standard Base64 decoder without padding.

The decoder requires reset before streaming and does not allocate.

§Returns

Returns an uninitialized decoder using the standard alphabet without required padding.

Source

pub fn url_safe() -> Self

Creates a strict URL-safe Base64 decoder with padding.

The decoder requires reset before streaming and does not allocate.

§Returns

Returns an uninitialized decoder using the URL-safe alphabet and required padding.

Source

pub fn url_safe_no_pad() -> Self

Creates a strict URL-safe Base64 decoder without padding.

The decoder requires reset before streaming and does not allocate.

§Returns

Returns an uninitialized decoder using the URL-safe alphabet without required padding.

Trait Implementations§

Source§

impl Debug for Base64Decoder

Source§

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

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

impl Default for Base64Decoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TranscodeDecoder for Base64Decoder

Source§

type DecodeError = MiscCodecError

Error type produced by the underlying codec or decode policy. Read more
Source§

impl Transcoder for Base64Decoder

Source§

type Input = u8

Input unit type accepted by this transcoder.
Source§

type Output = u8

Output unit type produced by this transcoder.
Source§

type Error = TranscodeDecodeError<MiscCodecError>

Complete error type produced by this transcoder.
Source§

fn max_transcode_output_len( &self, input_len: usize, ) -> Result<usize, CapacityError>

Returns an upper bound for the output capacity needed to transcode input_len units during the streaming phase. Read more
Source§

fn reset( &mut self, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::Error>

Resets stream state and emits stream-start output into output. Read more
Source§

fn transcode( &mut self, input: &[u8], input_index: usize, output: &mut [u8], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>

Converts available input units into output units. Read more
Source§

fn transcode_eof( &mut self, input: &[u8], input_index: usize, output: &mut [u8], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>

Converts source units after the caller has established end of input. Read more
Source§

fn finish( &mut self, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::Error>

Finishes internally retained output after all input has been supplied. Read more
Source§

fn max_reset_output_len(&self) -> Result<usize, CapacityError>

Returns an upper bound for output units emitted when resetting stream state. Read more
Source§

fn max_total_output_len(&self, input_len: usize) -> Result<usize, CapacityError>

Returns an upper bound for a complete reset -> transcode_eof -> finish stream. Read more
Source§

fn max_finish_output_len(&self) -> Result<usize, CapacityError>

Returns an upper bound for output units produced by stream finalization. Read more
Source§

fn transcode_complete_into( &mut self, input: &[Self::Input], output: &mut [Self::Output], ) -> Result<usize, Self::Error>

Runs a complete one-shot reset -> transcode -> finish stream. Read more

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.