cbor-js
The Concise Binary Object Representation (CBOR) data format (RFC 7049) implemented in pure JavaScript.
API
The CBOR
-object provides the following two functions:
CBOR.decode(data)
Take the ArrayBuffer object data and return it decoded as a JavaScript object.
CBOR.encode(data)
Take the JavaScript object data and return it encoded as a ArrayBuffer object.
Usage
Include cbor.js
in your or HTML page:
Then you can use it via the CBOR
-object in your code:
var initial = Hello: "World" ;var encoded = CBOR;var decoded = CBOR;
After running this example initial
and decoded
represent the same value.
Combination with WebSocket
The API was designed to play well with the WebSocket
object in the browser:
var websocket = url;websocketbinaryType = "arraybuffer";...websocket { var message = CBOR;};...websocket;