pocopine-codec 0.1.0

Shared encoding/codec utilities (base64, percent-encoding, serde adapters) for the pocopine workspace.
Documentation

Shared encoding / codec utilities for the pocopine workspace.

The point of this crate is that crates never re-implement encoding helpers or their serde adapters and never reach for base64 or percent-encoding directly. Add new codecs here rather than inlining them per crate.

use pocopine_codec::{base64_decode, base64_encode};

assert_eq!(base64_encode(b"hi"), "aGk=");
assert_eq!(base64_decode("aGk=").unwrap(), b"hi");

Percent-encoding goes through one component encoder (RFC 3986 "unreserved" set — what URL path segments, query parts, and fragments want) plus a lossy decoder. Pass a custom [AsciiSet] to [percent_encode_set] when a backend needs a different escape set.

use pocopine_codec::{percent_decode, percent_encode};

assert_eq!(percent_encode("a b/c~d"), "a%20b%2Fc~d");
assert_eq!(percent_decode("a%20b+c", true), "a b c");

For a Vec<u8> struct field that should serialize as a base64 string, use the [base64_bytes] serde adapter:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Chunk {
    #[serde(with = "pocopine_codec::base64_bytes", default, skip_serializing_if = "Vec::is_empty")]
    payload: Vec<u8>,
}

This crate is no_std (it only needs alloc).