Function decode

Source
pub fn decode(charset: &str, decode_str: &str) -> Result<String, DecodeError>
Expand description

decodes a given encoded string based on a specified charset, using 4-character groups to restore the original bytes. Each character in the decode_str string is mapped to an index in charset to form the decoded bytes.

§Parameters

  • charset: A string representing the character set used to encode and decode the data. Each character should have a unique position in charset.
  • decode_str: The string to be decoded, which was originally encoded with the provided charset.

§Returns

Returns a Result containing the decoded String if successful, or a DecodeError if the charset is invalid.

§Example

use bin_encode_decode::*;

let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=";
let encoded_str = "aab0aabLaabZaab0";
let decoded_str = decode(charset, encoded_str);
assert_eq!(decoded_str.unwrap(), "test");