rust_erl_ext

Crates.iorust_erl_ext
lib.rsrust_erl_ext
version0.2.1
sourcesrc
created_at2015-01-12 16:14:13.506596
updated_at2015-12-11 23:56:40.231265
descriptionErlang external term format codec.
homepage
repositoryhttps://github.com/seriyps/rust-erl-ext
max_upload_size
id773
size105,322
Sergey Prokhorov (seriyps)

documentation

README

Rust Erl Ext

Erlang external term format parser/serializer for Rust.

Build Status

Examples

Decoding

extern crate erl_ext;
use erl_ext::Decoder;

fn main() {
    let mut decoder = Decoder::new(&mut io::stdin());
    assert!(true == decoder.read_prelude().unwrap());
    println!("{}", decoder.decode_term().unwrap());
}

Encoding

extern crate erl_ext;
use erl_ext::{Eterm, Encoder};

fn main() {
    let term = Eterm::List(vec!(Eterm::SmallInteger(1),
                                Eterm::Integer(1000000),
                                Eterm::Nil));
    // this combination of options make it compatible with erlang:term_to_binary/1
    let utf8_atoms = false;
    let small_atoms = false;
    let fair_new_fun = true;
    let mut encoder = Encoder::new(&mut io::stdout(),
                                   utf8_atoms, small_atoms, fair_new_fun);
    encoder.write_prelude();
    encoder.encode_term(term);
}

More examples are in examples directory.

Types (all Erlang 17.1 types are supported):

  • SmallInteger (u8) : 0..255

  • Integer (i32) : integer()

  • Float (f64) : float()

  • Atom (String) : atom()

  • Reference : reference() erlang:make_ref/0

  • Port : port() eg, socket or raw file or erlang:open_port/2

  • Pid : pid()

  • Tuple (Vec<Eterm>) : { any() }

  • Map (Vec<(Eterm, Eterm)>) : #{any() := any()}

  • Nil : []

  • String (Vec<u8>) : [0..255]

  • List (Vec<Eterm>) : [ any() ]

  • Binary (Vec<u8>) : binary()

  • BigNum (BigInt) : integer() > i32

  • Fun : fun(..) -> ... end. - deprecated variant

  • NewFun : fun(..) -> ... end.

  • Export : fun my_mod:my_fun/1

  • BitBinary : <<128, 128:4>>

TODO

  • serialize::Decoder and serialize::Encoder implementations (not so easy for containers)
  • Quick-Check - like tests (feed pseudo-random bytes to decoder, feed random Eterm's to encoder)

Keywords

  • Rust
  • Erlang
  • BERT
  • External term format
  • term_to_binary, binary_to_term
  • parser, serializer
Commit count: 49

cargo fmt