| Crates.io | entidb_codec |
| lib.rs | entidb_codec |
| version | 2.0.0-alpha.3 |
| created_at | 2025-12-25 14:43:04.542908+00 |
| updated_at | 2026-01-03 03:14:47.933994+00 |
| description | Canonical CBOR encoding/decoding for EntiDB |
| homepage | |
| repository | https://github.com/Tembocs/entidb |
| max_upload_size | |
| id | 2004616 |
| size | 64,987 |
Canonical CBOR encoding/decoding for EntiDB.
This crate provides a strict canonical CBOR implementation following RFC 8949 Section 4.2.1 deterministic encoding rules. It is designed specifically for EntiDB's requirements where byte-exact reproducibility is mandatory.
use entidb_codec::{to_canonical_cbor, from_cbor, Value};
// Create a value
let value = Value::map(vec![
(Value::Text("name".into()), Value::Text("Alice".into())),
(Value::Integer(42), Value::Bool(true)),
]);
// Encode to canonical CBOR bytes
let bytes = to_canonical_cbor(&value)?;
// Decode back (validates canonicity)
let decoded = from_cbor(&bytes)?;
assert_eq!(value, decoded);
| Type | Description |
|---|---|
Value::Null |
CBOR null (0xf6) |
Value::Bool(bool) |
CBOR true/false |
Value::Integer(i64) |
Signed integer (types 0 and 1) |
Value::Bytes(Vec<u8>) |
Byte string (type 2) |
Value::Text(String) |
UTF-8 text string (type 3) |
Value::Array(Vec<Value>) |
Array (type 4) |
Value::Map(BTreeMap<Value, Value>) |
Map (type 5, sorted) |
The decoder returns CodecError for:
FloatForbidden - Float values encounteredIndefiniteLengthForbidden - Indefinite-length encoding usedInvalidUtf8 - Non-UTF-8 text stringInvalidStructure - Non-canonical encoding (unsorted keys, non-shortest integers)UnexpectedEof - Truncated inputThis crate is a foundational dependency for entidb_core. All entity payloads stored in EntiDB use this canonical encoding to ensure:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.