DoxigAlpha

calcSizeForSlice

Return the exact decoded size for a slice. InvalidPadding is returned if the input length is not valid.

Function parameters

Parameters

#
decoder:*const Base64Decoder
source:[]const u8

Base64 codecs

Types

#
Codecs
Base64 codecs

Error sets in this namespace

Error Sets

#

The Base64 alphabet defined in

Values

#
standard_alphabet_chars
The Base64 alphabet defined in
standard
Standard Base64 codecs, with padding, as defined in
standard_no_pad
Standard Base64 codecs, without padding, as defined in
url_safe_alphabet_chars
The URL-safe Base64 alphabet defined in
url_safe
URL-safe Base64 codecs, with padding, as defined in
url_safe_no_pad
URL-safe Base64 codecs, without padding, as defined in

Source

Implementation

#
pub fn calcSizeForSlice(decoder: *const Base64Decoder, source: []const u8) Error!usize {
    const source_len = source.len;
    var result = try decoder.calcSizeUpperBound(source_len);
    if (decoder.pad_char) |pad_char| {
        if (source_len >= 1 and source[source_len - 1] == pad_char) result -= 1;
        if (source_len >= 2 and source[source_len - 2] == pad_char) result -= 1;
    }
    return result;
}