pub fn decode(
encoded: &str,
alphabet: &Alphabet,
) -> Result<Vec<u8>, DecodeError>Expand description
Decodes a string back to binary data using the specified alphabet.
Automatically selects the appropriate decoding strategy based on the alphabet’s mode (BaseConversion, Chunked, or ByteRange).
§Arguments
encoded- The encoded string to decodealphabet- The alphabet used for encoding
§Returns
A Result containing the decoded binary data, or a DecodeError if
the input is invalid
§Errors
Returns DecodeError if:
- The input contains invalid characters
- The input is empty
- The padding is invalid (for chunked mode)
§Examples
use base_d::{Alphabet, EncodingMode, encode, decode};
let chars: Vec<char> = "01".chars().collect();
let alphabet = Alphabet::new_with_mode(chars, EncodingMode::BaseConversion, None)?;
let data = b"Hi";
let encoded = encode(data, &alphabet);
let decoded = decode(&encoded, &alphabet)?;
assert_eq!(data, &decoded[..]);