#bson #codec #support #decoding #document #binary

bson-rs

Encoding and decoding support for BSON in Rust

3 releases

Uses old Rust 2015

0.1.0 May 28, 2015
0.0.3 May 24, 2015
0.0.2 Apr 9, 2015
0.0.1 Apr 8, 2015

#31 in #bson

MIT license

39KB
691 lines

bson-rs

Build Status crates.io

Encoding and decoding support for BSON in Rust

[dependencies]
bson-rs = "*"

lib.rs:

BSON is a binary format in which zero or more key/value pairs are stored as a single entity. We call this entity a document.

This library supports Version 1.0 of BSON standard.

Basic usage

extern crate bson;
use std::io::Cursor;
use bson::{Bson, Document, Encoder, Decoder};

fn main() {
    let mut doc = Document::new();
    doc.insert("foo".to_string(), Bson::String("bar".to_string()));

    let mut buf = Vec::new();
    {
        let mut enc = Encoder::new(&mut buf);
        enc.encode_document(&doc).unwrap();
    }

    let mut r = Cursor::new(&buf[..]);
    {
        let mut dec = Decoder::new(&mut r);
        let doc = dec.decode_document().unwrap();
    }
}

Dependencies

~1.5MB
~25K SLoC