How to use the cbor.Encoder function in cbor

To help you get started, we’ve selected a few cbor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github radixdlt / radixdlt-js / src / modules / atommodel / serializer / RadixSerializer.ts View on Github external
public static toDSON(data: any): Buffer {
        const enc = new cbor.Encoder()

        // Overide default object encoder to use stream encoding and lexicographical ordering of keys
        enc.addSemanticType(Object, (encoder, obj) => {
            const keys = Object.keys(obj)

            keys.sort()

            if (!encoder.push(Buffer.from([0b1011_1111]))) { return false }

            for (const key of keys) {
                if (isEmpty(obj[key])) {
                    continue
                }

                if (!encoder.pushAny(key)) { return false }
                if (!encoder.pushAny(obj[key])) { return false }
github hyperledger / sawtooth-core / clients / javascript / lib / signed_object.js View on Github external
var _toCBOR = function(signableObj) {
    var encoder = new cbor.Encoder();
    var output = new streamBuffers.WritableStreamBuffer({
        initalSize: (16 * 1024),
    });
    encoder.pipe(output);

    encoder.write(signableObj.sortBy(_byKey).toJSON());

    encoder.end();
    return output.getContents();
};

cbor

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis