• Home
Name Date Size #Lines LOC

..--

examples/03-May-2024-12583

src/03-May-2024-4,5403,336

tests/03-May-2024-1,7431,488

.cargo_vcs_info.jsonD03-May-202474 65

.gitignoreD03-May-202486 98

.travis.ymlD03-May-20241.1 KiB2927

Android.bpD03-May-20245.7 KiB233208

CONTRIBUTING.mdD03-May-20241.2 KiB2924

Cargo.tomlD03-May-20241.2 KiB4540

Cargo.toml.origD03-May-2024837 3429

LICENSED03-May-202410.6 KiB202169

LICENSE-APACHED03-May-202410.6 KiB202169

LICENSE-MITD03-May-20241 KiB2016

METADATAD03-May-2024374 2019

MODULE_LICENSE_APACHE2D03-May-20240

OWNERSD03-May-202440 21

README.mdD03-May-20242.6 KiB8062

TEST_MAPPINGD03-May-2024674 3332

README.md

1# Serde CBOR
2[![Build Status](https://travis-ci.org/pyfisch/cbor.svg?branch=master)](https://travis-ci.org/pyfisch/cbor)
3[![Crates.io](https://img.shields.io/crates/v/serde_cbor.svg)](https://crates.io/crates/serde_cbor)
4[![Documentation](https://docs.rs/serde_cbor/badge.svg)](https://docs.rs/serde_cbor)
5
6This crate implements the Concise Binary Object Representation from [RFC 7049].
7It builds on [Serde], the generic serialization framework for Rust.
8CBOR provides a binary encoding for a superset
9of the JSON data model that is small and very fast to parse.
10
11[RFC 7049]: https://tools.ietf.org/html/rfc7049
12[Serde]: https://github.com/serde-rs/serde
13
14## Usage
15
16Serde CBOR supports Rust 1.40 and up. Add this to your `Cargo.toml`:
17```toml
18[dependencies]
19serde_cbor = "0.11.1"
20```
21
22Storing and loading Rust types is easy and requires only
23minimal modifications to the program code.
24
25```rust
26use serde_derive::{Deserialize, Serialize};
27use std::error::Error;
28use std::fs::File;
29
30// Types annotated with `Serialize` can be stored as CBOR.
31// To be able to load them again add `Deserialize`.
32#[derive(Debug, Serialize, Deserialize)]
33struct Mascot {
34    name: String,
35    species: String,
36    year_of_birth: u32,
37}
38
39fn main() -> Result<(), Box<dyn Error>> {
40    let ferris = Mascot {
41        name: "Ferris".to_owned(),
42        species: "crab".to_owned(),
43        year_of_birth: 2015,
44    };
45
46    let ferris_file = File::create("examples/ferris.cbor")?;
47    // Write Ferris to the given file.
48    // Instead of a file you can use any type that implements `io::Write`
49    // like a HTTP body, database connection etc.
50    serde_cbor::to_writer(ferris_file, &ferris)?;
51
52    let tux_file = File::open("examples/tux.cbor")?;
53    // Load Tux from a file.
54    // Serde CBOR performs roundtrip serialization meaning that
55    // the data will not change in any way.
56    let tux: Mascot = serde_cbor::from_reader(tux_file)?;
57
58    println!("{:?}", tux);
59    // prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 }
60
61    Ok(())
62}
63```
64
65There are a lot of options available to customize the format.
66To operate on untyped CBOR values have a look at the `Value` type.
67
68## License
69Licensed under either of
70
71 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
72 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
73
74at your option.
75
76### Contribution
77Unless you explicitly state otherwise, any contribution intentionally submitted
78for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
79additional terms or conditions.
80