Interface for types that can be decoded from CBOR.
This interface serves as a marker to indicate that a type
supports being created from CBOR data.
Example
// Custom type that can be decoded from CBOR classPersonimplementsCborDecodable<Person> { constructor(publicname: string = '', publicage: number = 0) {}
staticfromCbor(cbor: Cbor): Person { if (cbor.type !== MajorType.Map) { thrownewError('Expected a CBOR map'); } constmap = cbor.valueasCborMap; constname = extractCbor(map.get(cbor('name'))!) asstring; constage = extractCbor(map.get(cbor('age'))!) asnumber; returnnewPerson(name, age); }
tryFromCbor(cbor: Cbor): Person { returnPerson.fromCbor(cbor); } }
// Parse from CBOR constcborMap = ...; // some CBOR map constperson = Person.fromCbor(cborMap);
Interface for types that can be decoded from CBOR.
This interface serves as a marker to indicate that a type supports being created from CBOR data.
Example