BC-DCBOR TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Interface CborEncodable

    Interface for types that can be encoded to CBOR.

    This interface provides convenient methods for converting instances into CBOR objects and binary data.

    // Custom type that can convert to CBOR
    class Person implements CborEncodable {
    constructor (public name: string, public age: number) {}

    toCbor(): Cbor {
    const map = new CborMap();
    map.set(cbor('name'), cbor(this.name));
    map.set(cbor('age'), cbor(this.age));
    return cbor(map);
    }

    toCborData(): Uint8Array {
    return cborData(this.toCbor());
    }
    }

    // Use the interface
    const person = new Person('Alice', 30);

    // Convert to CBOR
    const cborValue = person.toCbor();

    // Convert directly to binary CBOR data
    const data = person.toCborData();
    interface CborEncodable {
        toCbor(): Cbor;
        toCborData(): Uint8Array;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Converts this value directly to binary CBOR data.

      This is a shorthand for cborData(this.toCbor()).

      Returns Uint8Array

      Binary CBOR data