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
impl Base64Decoder
Sourcepub fn standard() -> Self
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.
Sourcepub fn standard_no_pad() -> Self
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.
Sourcepub fn url_safe() -> Self
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.
Sourcepub fn url_safe_no_pad() -> Self
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
impl Debug for Base64Decoder
Source§impl Default for Base64Decoder
impl Default for Base64Decoder
Source§impl TranscodeDecoder for Base64Decoder
impl TranscodeDecoder for Base64Decoder
Source§type DecodeError = MiscCodecError
type DecodeError = MiscCodecError
Domain error type produced when Base64 input cannot be decoded.
Source§impl Transcoder for Base64Decoder
impl Transcoder for Base64Decoder
Source§type Error = TranscodeDecodeError<MiscCodecError>
type Error = TranscodeDecodeError<MiscCodecError>
Errors produced by invalid input or invalid stream state.
Source§fn max_transcode_output_len(
&self,
input_len: usize,
) -> Result<usize, CapacityError>
fn max_transcode_output_len( &self, input_len: usize, ) -> Result<usize, CapacityError>
Returns a checked upper bound for decoding input_len encoded bytes.
§Parameters
input_len: Number of encoded input bytes to decode.
§Returns
Returns the maximum number of decoded bytes required for that input length.
§Errors
Returns CapacityError when the output bound overflows usize.
Source§fn reset(
&mut self,
output: &mut [u8],
output_index: usize,
) -> Result<usize, Self::Error>
fn reset( &mut self, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::Error>
Starts a fresh stream and clears terminal-padding state.
§Parameters
output: Output buffer available to the reset phase.output_index: Starting position inoutput; must not exceed its length.
§Returns
Returns the number of output elements written during reset (zero).
§Errors
Returns an invalid-output-index error when output_index exceeds the
buffer length.
Source§fn transcode(
&mut self,
input: &[u8],
input_index: usize,
output: &mut [u8],
output_index: usize,
) -> Result<TranscodeProgress, Self::Error>
fn transcode( &mut self, input: &[u8], input_index: usize, output: &mut [u8], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>
Decodes the visible input without treating its end as source EOF.
§Parameters
input: Visible encoded bytes; unconsumed bytes must be supplied again on a later call.input_index: Starting position ininput; must not exceed its length.output: Destination buffer for decoded bytes.output_index: Starting position inoutput; must not exceed its length.
§Returns
Returns progress describing consumed input, written output, and whether more input or output capacity is needed.
§Errors
Returns invalid-index or lifecycle errors, or a Base64 domain error for invalid input. A domain error poisons the stream until reset.
Source§fn transcode_eof(
&mut self,
input: &[u8],
input_index: usize,
output: &mut [u8],
output_index: usize,
) -> Result<TranscodeProgress, Self::Error>
fn transcode_eof( &mut self, input: &[u8], input_index: usize, output: &mut [u8], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>
Decodes input after the caller has confirmed source EOF.
§Parameters
input: Visible encoded bytes, including any previously unconsumed tail.input_index: Starting position ininput; must not exceed its length.output: Destination buffer for decoded bytes.output_index: Starting position inoutput; must not exceed its length.
§Returns
Returns progress describing consumed input, written output, and whether more output capacity is needed.
§Errors
Returns invalid-index or lifecycle errors, or a Base64 domain error for invalid or incomplete EOF input. A domain error poisons the stream until reset.
Source§fn finish(
&mut self,
output: &mut [u8],
output_index: usize,
) -> Result<usize, Self::Error>
fn finish( &mut self, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::Error>
Marks a successfully decoded stream as finished.
§Parameters
output: Output buffer available to the finish phase.output_index: Starting position inoutput; must not exceed its length.
§Returns
Returns the number of output elements written during finish (zero).
§Errors
Returns an invalid-output-index error or a lifecycle error when the stream is not ready to finish.
Source§fn max_reset_output_len(&self) -> Result<usize, CapacityError>
fn max_reset_output_len(&self) -> Result<usize, CapacityError>
Source§fn max_total_output_len(&self, input_len: usize) -> Result<usize, CapacityError>
fn max_total_output_len(&self, input_len: usize) -> Result<usize, CapacityError>
reset -> transcode_eof -> finish
stream. Read more