Skip to main content

CBORDecoding

CBORDecoding​

Solidity library built for decoding CBOR data.

decodeMapping​

function decodeMapping(bytes encoding) external view returns (bytes[2][] decodedData)

Parses an encoded CBOR Mapping into a 2d array of data

NameTypeDescription
encodingbytesEncoded CBOR bytes data
NameTypeDescription
decodedDatabytes[2][]Decoded CBOR data (returned in 2d array). Interpretting this bytes data from bytes to it's proper object is up to the implementer.

decodeArray​

function decodeArray(bytes encoding) external view returns (bytes[] decodedData)

Parses an encoded CBOR array into a bytes array of its data

NameTypeDescription
encodingbytesEncoded CBOR bytes data
NameTypeDescription
decodedDatabytes[]Decoded CBOR data (returned in array). Interpretting this bytes data from bytes to it's proper object is up to the implementer.

decodePrimitive​

function decodePrimitive(bytes encoding) external view returns (bytes decodedData)

Parses an encoded CBOR dynamic bytes array into it's array of data

NameTypeDescription
encodingbytesEncoded CBOR bytes data
NameTypeDescription
decodedDatabytesDecoded CBOR data (returned in structs). Interpretting this bytes data from bytes to it's proper object is up to the implementer.

decodeMappingGetValue​

function decodeMappingGetValue(bytes encoding, bytes searchKey) external view returns (bytes value)

Performs linear search through mapping for a key. This is much cheaper than decoding an entire mapping and then searching through it for a key.

NameTypeDescription
encodingbytesencoded CBOR bytes data
searchKeybyteskey to search for
NameTypeDescription
valuebytesdecoded CBOR data as bytes

decodeArrayGetIndex​

function decodeArrayGetIndex(bytes encoding, bytes searchKey) external view returns (uint64 index)

Performs linear loop through a CBOR array until `searchKey` is found, and returns the corresponding index.

NameTypeDescription
encodingbytesencoded CBOR bytes data
searchKeybyteskey to search for
NameTypeDescription
indexuint64item position in items where item exists

decodeArrayGetItem​

function decodeArrayGetItem(bytes encoding, uint64 index) external view returns (bytes value)

Returns the value of the Nth item in an array.

NameTypeDescription
encodingbytesencoded CBOR bytes data
indexuint64Nth item index to grab
NameTypeDescription
valuebytesdecoded CBOR data as bytes