json-packer 0.1.0

Reversible JSON binary compression/decompression library with Huffman-encoded keys and optional string value pooling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use base64::engine::general_purpose::{STANDARD, STANDARD_NO_PAD};
use base64::Engine as _;

use crate::Error;

pub fn encode_base64(bytes: &[u8]) -> String {
    STANDARD_NO_PAD.encode(bytes)
}

pub fn decode_base64(s: &str) -> Result<Vec<u8>, Error> {
    match STANDARD_NO_PAD.decode(s) {
        Ok(v) => Ok(v),
        Err(_) => Ok(STANDARD.decode(s)?),
    }
}