Skip to content
forked from paroga/cbor-js

The Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript (ES Module). CBOR.js

License

Notifications You must be signed in to change notification settings

code4fukui/CBOR-es

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CBOR-es

The Concise Binary Object Representation (CBOR) data format (RFC 7049) implemented in pure JavaScript (ES Module).

API

The CBOR-object provides the following two functions:

CBOR.decode(data)

Take the Uint8Array object data and return it decoded as a JavaScript object.

CBOR.encode(data)

Take the JavaScript object data and return it encoded as a Uint8Array object.

Usage

Include CBOR.js in your or HTML page:

import { CBOR } from "https://code4fukui.github.io/CBOR-es/CBOR.js";

const initial = { Hello: "World" };
const encoded = CBOR.encode(initial);
const decoded = CBOR.decode(encoded);

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:

const websocket = new WebSocket(url);
websocket.binaryType = "arraybuffer";
...
websocket.onmessage = (event) => {
  const message = CBOR.decode(new Uint8Array(event.data));
};
...
websocket.send(CBOR.encode(message));

About

The Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript (ES Module). CBOR.js

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 100.0%