x0id / erlb.js

Javascript binary support of Erlang External Term Format

Home Page:http://saleyn.github.com/erlb.js/erlb-test.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

erlb.js

Javascript binary support of Erlang External Term Format (ETF)

Installation

git clone https://github.com/saleyn/erlb.js.git

Include erlb.js to your project.

Interface

  • Erl.encode(Object) - Encode a Javascript object into ETF, return ArrayBuffer suitable for sending via websocket. The object can be a Boolean, Integer, Float, String, Array, Object (treated as a proplist) or an Atom, Binary, or Tuple (with the help of Erl.atom(), Erl.binary(), or Erl.tuple(), respectively).
  • Erl.decode(ArrayBuffer) - Decode a binary ArrayBuffer into a Javascript object.
  • Erl.equals(Obj1, Obj2) - Compare Obj1 and Obj2 for equality.
  • Erl.toString(Obj) - Print a Javascript object in the Erlang notation.
  • Erl.atom(String) - Create a Javascript object that will be encoded to an Atom.
  • Erl.binary(UInt8Array) - Create a Javascript object that will be encoded to an Binary.
  • Erl.tuple(Array) - Create a Javascript object that will be encoded to a Tuple.
  • Erl.pid(Node, Id, Ser, Creation) - Create a Javascript object that will be encoded to a Pid.
  • Erl.ref(Node, Creation, IDs) - Create a Javascript object that will be encoded to a Ref.

The library natively understands the following Javascript types:

  • Number (integer, float)
  • String
  • Boolean
  • Array (Erlang list)
  • Object (Erlang proplists)

Utility Functions

  • Erl.toArrayBuffer(Array) - Convert array of bytes to a binary buffer.
  • Erl.bufferToArray(ArrayBuffer) - Convert a binary buffer to an array of bytes.
  • Erl.timestampToTuple(Int) - Convert a timestamp (number of ms since epoch) to {MegaSec, Sec, MicroSec} tuple.
  • Erl.dateToTuple(Date) - Convert a Javascript Date to {MegaSec, Sec, MicroSec} tuple.

Testing

You can use provided bin/simple_http_server to serve the content of the current directory to a web browser:

$ bin/simple_http_server 8000

Point your browser to http://localhost:8000/erlb-test.html. The page automatically runs all unit tests defined in the erlb-test.js script.

Author

Serge Aleynikov <saleyn at gmail dot com>

License

BSD License (see included LICENSE file)

About

Javascript binary support of Erlang External Term Format

http://saleyn.github.com/erlb.js/erlb-test.html

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:JavaScript 95.8%Language:Makefile 1.4%Language:Python 1.4%Language:HTML 1.4%