#serde #cbor #serialization #no-std

no-std cs_serde_cbor

CBOR support for serde

1 unstable release

0.12.0 Nov 10, 2020

#418 in Encoding

Download history 193/week @ 2021-06-26 177/week @ 2021-07-03 262/week @ 2021-07-10 172/week @ 2021-07-17 55/week @ 2021-07-24 66/week @ 2021-07-31 113/week @ 2021-08-07 129/week @ 2021-08-14 74/week @ 2021-08-21 70/week @ 2021-08-28 41/week @ 2021-09-04 40/week @ 2021-09-11 100/week @ 2021-09-18 172/week @ 2021-09-25 39/week @ 2021-10-02 162/week @ 2021-10-09

578 downloads per month
Used in 14 crates (via forest_encoding)


3.5K SLoC

Serde CBOR

Build Status Crates.io Documentation

This crate implements the Concise Binary Object Representation from RFC 7049. It builds on Serde, the generic serialization framework for Rust. CBOR provides a binary encoding for a superset of the JSON data model that is small and very fast to parse.


Serde CBOR supports Rust 1.40 and up. Add this to your Cargo.toml:

serde_cbor = "0.11.1"

Storing and loading Rust types is easy and requires only minimal modifications to the program code.

use serde_derive::{Deserialize, Serialize};
use std::error::Error;
use std::fs::File;

// Types annotated with `Serialize` can be stored as CBOR.
// To be able to load them again add `Deserialize`.
#[derive(Debug, Serialize, Deserialize)]
struct Mascot {
    name: String,
    species: String,
    year_of_birth: u32,

fn main() -> Result<(), Box<dyn Error>> {
    let ferris = Mascot {
        name: "Ferris".to_owned(),
        species: "crab".to_owned(),
        year_of_birth: 2015,

    let ferris_file = File::create("examples/ferris.cbor")?;
    // Write Ferris to the given file.
    // Instead of a file you can use any type that implements `io::Write`
    // like a HTTP body, database connection etc.
    serde_cbor::to_writer(ferris_file, &ferris)?;

    let tux_file = File::open("examples/tux.cbor")?;
    // Load Tux from a file.
    // Serde CBOR performs roundtrip serialization meaning that
    // the data will not change in any way.
    let tux: Mascot = serde_cbor::from_reader(tux_file)?;

    println!("{:?}", tux);
    // prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 }


There are a lot of options available to customize the format. To operate on untyped CBOR values have a look at the Value type.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.