minicbor-ser
This repository provides a simple implementation of serde for minicbor, making it easier to use.
Quick start
Just like using other serde derived libraries:
[]
= "0.1.*"
- Serialization
use minicbor_ser as cbor;
use Serialize;
- Deserialization
use minicbor_ser as cbor;
use Deserialize;
By default, structs will be serialized as map and tuples will be serialized as array. If you don't want to wrap top-level struct and tuple with map and array, you can use to_vec_flat. To deserialize you should use from_slice_flat.
let expect = ;
let tuple_flatten = ;
let value = to_vec_flat.unwrap;
assert_eq!
let data = crateto_vec_flat.unwrap;
let value = from_slice_flat.unwrap;
assert_eq!;
Type mapping table
The following represents how the minicbor-ser will map the types of Rust and CBOR
- ❌ : Not support
- ⚠ : Not perfect yet
| Rust | CBOR |
|---|---|
| unsigned integer | unsigned integer |
| negative Integer | negative Integer |
| u128 | ❌ |
| i128 | ❌ |
| &str | String |
| String | String |
| struct | map (if flatten_top is false) |
| Map | map |
| slice | array (if flatten_top is false) |
| &[u8] | bytes |
| tuple | array (if flatten_top is false) |
| Vec | array (if flatten_top is false) |
| Vec | Bytes |
| newtype variant | map |
| unit variant | String |
| tuple variant | array |
| struct variant | map |
no-std
The current no-std feature of minicbor-ser requires alloc. If your machine cannot use alloc, it is recommended that you use the derive feature that comes with minicbor.
To enable no-std, use :
[]
= { = "0.1.*", = false }
Note
Some types of serialization and deserialization may be different from minicbor, depending on how minicbor is implemented.
If you need the default implementation of minicbor, please use minicbor_ser::cbor to access its API.