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 CBORclass 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 interfaceconst person = new Person('Alice', 30);// Convert to CBORconst cborValue = person.toCbor();// Convert directly to binary CBOR dataconst data = person.toCborData(); Copy
// Custom type that can convert to CBORclass 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 interfaceconst person = new Person('Alice', 30);// Convert to CBORconst cborValue = person.toCbor();// Convert directly to binary CBOR dataconst data = person.toCborData();
Converts this value to a CBOR object.
CBOR representation
Converts this value directly to binary CBOR data.
This is a shorthand for cborData(this.toCbor()).
cborData(this.toCbor())
Binary CBOR data
Interface for types that can be encoded to CBOR.
This interface provides convenient methods for converting instances into CBOR objects and binary data.
Example