cbor-wrapper
v0.0.1
Published
A wrapper for cbor lib
Downloads
3
Readme
cbor-wrapper
A wrapper for cbor lib
Peer dependencies
- cbor (required)
- buffer (optional) .Please install buffer if you get error message 'Cannot find variable buffer') https://stackoverflow.com/questions/48432524/cant-find-variable-buffer
import buffer from 'buffer';
global.Buffer = buffer.Buffer;
Encode
import cborWrapper from 'cbor-wrapper';
async function encode(data) {
const encodedData = await cborWrapper.encode(data); // Buffer <01, 02, 05, ...>
return encodedData;
}
Serialize data to string
import cborWrapper from 'cbor-wrapper';
async function serialize(data) {
const encodedData = await cborWrapper.encode(data, true); // "binary string ..."
return encodedData;
}
Decode
import cborWrapper from 'cbor-wrapper';
async function decode() {
await cborWrapper.decode('{ "text": "Hello World" }'); // support JSON serialized string
await cborWrapper.decode('binary string'); // support binary string
await cborWrapper.decode('01EFC3....'); // support hex string
await cborWrapper.decode(Buffer.alloc(4000)); // support buffer object
}