Function const_base::encoded_len

source ·
pub const fn encoded_len(unencoded_length: usize, config: Config) -> usize
Expand description

Computes the length of the encoded string from the unencoded_length, using the encoding determined by config.

Example

Base64

use const_base::{Config, encoded_len};

const BASE64: usize = encoded_len(4, Config::B64);
assert_eq!(BASE64, 8);

// `.end_padding(false)` removes that trailing `=` that pads the string to
// a multiple of 4 bytes long.
const BASE64_UNPAD: usize = encoded_len(4, Config::B64.end_padding(false));
assert_eq!(BASE64_UNPAD, 6);

Base32

use const_base::{Config, encoded_len};

const BASE32: usize = encoded_len(3, Config::B32);
assert_eq!(BASE32, 8);

// `.end_padding(false)` removes that trailing `=` that pads the string to
// a multiple of 8 bytes long.
const BASE32_UNPAD: usize = encoded_len(3, Config::B32.end_padding(false));
assert_eq!(BASE32_UNPAD, 5);

Hexadecimal

use const_base::{Config, encoded_len};

const HEX_4: usize = encoded_len(4, Config::HEX);
const HEX_6: usize = encoded_len(6, Config::HEX);
assert_eq!(HEX_4, 8);
assert_eq!(HEX_6, 12);