Serde adapter for controlling the representation of bytes
Human readable formats tend not to include a universally agreed way to represent arbitrary binary data, which means those serde libraries can end up using a representation for serde's "bytes" type which isn't ideal for all uses.
// [dependencies]
// serde = { version = "1.0", features = ["derive"] }
// serde_bytes = "0.11"
// serde_json = "1.0"
// serde_yaml = "0.8"
// toml = "0.5"
use Serialize;
JSON: {"bytes":[116,101,115,116,105,110,103]}
YAML: ---
bytes:
- 116
- 101
- 115
- 116
- 105
- 110
- 103
TOML: bytes = [116, 101, 115, 116, 105, 110, 103]
This adapter lets you control how the bytes are represented by wrapping a serializer like this:
Outputs:
JSON(base64): {"bytes":"dGVzdGluZw=="}