bert

Crates.iobert
lib.rsbert
version0.1.0
sourcesrc
created_at2016-11-11 23:43:07.667786
updated_at2016-11-11 23:43:07.667786
descriptionBERT (Binary ERlang Term) serializer
homepage
repositoryhttps://github.com/Relrin/bert-rs
max_upload_size
id7210
size42,506
Valeryi Savich (Relrin)

documentation

README

bert-rs

BERT (Binary ERlang Term) serializer Build Status

This crate provide an access to serializing data to the special binary data format, which can be send to your Erlang programs. The implementation relies on the BERT and Erlang External Term Format specifications.

Dependencies

For a work with bert-rs you will need few libraries, which should be specified at your Cargo.toml file:

serde = "0.8.7"
num = "0.1.34"
byteorder = "0.5.3"

License

The bert-rs published under BSD license. For more details read LICENSE file.

Example of using

The bert-rs crate provide a support for default Rust types and some additional, which have specified in BERT document. For any supported type of data which should be serialized you will pass into term_to_binary function:

#![feature(proc_macro)]

extern crate bert;
extern crate serde;


#[derive(Debug, PartialEq, Serialize)]
struct Point2D(i32, i32);


fn main() {
    let point = Point2D(1, 2);

    // serialized to {point2d, 1, 2} in BERT format
    let serialized_point_2d = bert::term_to_binary(&point).unwrap(); 
    assert_eq!(
        serialized_point_2d
        vec![
            131u8,
            105,                                          // tuple
            0, 0, 0, 3,                                   // length
            100, 0, 7, 112, 111, 105, 110, 116, 50, 100,  // "point2d" as atom
            98, 0, 0, 0, 1,                               // 1
            98, 0, 0, 0, 2                                // 2
        ]   
    );
}

Note: At the moment bert-rs provide only serialize features. But bert-rs have the serder-rs-deserializer branch, where this library provide deserialize functionality. The part of required stuff is not implemented (because of issues with too complicated approaches of deserializing): list, tuples, BertBigInteger and special kind of tuples which represented as {bert, ...}. If you want to help in further development, then feel free to open pull requests and issues.

For development used:

  • rustup toolchain
  • stable rustc 1.11.0 (9b21dcd6a 2016-08-15) for building releases
  • unstable rustc 1.13.0-nightly (3c5a0fa45 2016-08-22) for testing
Commit count: 76

cargo fmt