pub struct Base64Codec {
pub encode: bool,
pub columns: usize,
pub carry: u8,
pub position: usize,
pub line_position: usize,
pub finished: bool,
}Expand description
Plain state of one Base64 stream, restorable between successful calls.
Each call checks the state before reading input or writing output. The fields describe a logical state, with no Rust or C layout guarantee.
Fields§
§encode: boolTrue for encoding and false for decoding.
columns: usizeEncoded line width, or zero for a single line. Ignored by the decoder.
carry: u8Previous input byte (encoding) or sextet (decoding).
position: usizeBytes carried by the encoder or characters seen in the decoder group.
line_position: usizeNumber of characters on the current encoded line. Zero for decoding.
finished: boolThe stream has finished, or the decoder has started reading padding.
Implementations§
Source§impl Base64Codec
impl Base64Codec
Sourcepub const fn new(encode: bool, columns: usize) -> Self
pub const fn new(encode: bool, columns: usize) -> Self
Start a stream with the specified direction and encoded line width.
Sourcepub fn encoded_capacity(columns: usize, size: usize) -> Option<usize>
pub fn encoded_capacity(columns: usize, size: usize) -> Option<usize>
Upper bound for encoding a chunk and finalizing, including spare room
for a caller’s terminator. Returns None on arithmetic overflow.
Sourcepub fn decoded_capacity(size: usize) -> Option<usize>
pub fn decoded_capacity(size: usize) -> Option<usize>
Upper bound for decoding a chunk, including spare room to consume
padding. Returns None on arithmetic overflow.
Sourcepub fn update(
&mut self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, Base64Error>
pub fn update( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, Base64Error>
Consume all input and return the number of output bytes written.
After an error, discard the stream and any output from this call. A successful call can be followed by another with a different slice.
§Errors
Returns Base64Error::Invalid for invalid input or state, or
Base64Error::OutputFull when the output has insufficient space.
Sourcepub fn finish(&mut self, output: &mut [u8]) -> Result<usize, Base64Error>
pub fn finish(&mut self, output: &mut [u8]) -> Result<usize, Base64Error>
Complete the stream, writing any final encoded characters and padding.
A nonempty output slice is required. Encoding leaves one spare byte for the caller. Decoding returns zero and rejects an incomplete group. After an error, discard the stream and any output from this call. A successful call closes the stream.
§Errors
Returns Base64Error::Invalid for invalid state,
Base64Error::OutputFull when the output has insufficient space,
or Base64Error::Truncated for an incomplete decoder group.