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
| Name | Type | Description |
|---|---|---|
| encoding | bytes | Encoded CBOR bytes data |
| Name | Type | Description |
|---|---|---|
| decodedData | bytes[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
| Name | Type | Description |
|---|---|---|
| encoding | bytes | Encoded CBOR bytes data |
| Name | Type | Description |
|---|---|---|
| decodedData | bytes[] | 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
| Name | Type | Description |
|---|---|---|
| encoding | bytes | Encoded CBOR bytes data |
| Name | Type | Description |
|---|---|---|
| decodedData | bytes | Decoded 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.
| Name | Type | Description |
|---|---|---|
| encoding | bytes | encoded CBOR bytes data |
| searchKey | bytes | key to search for |
| Name | Type | Description |
|---|---|---|
| value | bytes | decoded 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.
| Name | Type | Description |
|---|---|---|
| encoding | bytes | encoded CBOR bytes data |
| searchKey | bytes | key to search for |
| Name | Type | Description |
|---|---|---|
| index | uint64 | item 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.
| Name | Type | Description |
|---|---|---|
| encoding | bytes | encoded CBOR bytes data |
| index | uint64 | Nth item index to grab |
| Name | Type | Description |
|---|---|---|
| value | bytes | decoded CBOR data as bytes |