Skip to main content

CBORDataStructures

CBORDataStructures

Solidity library built for decoding CBOR data.

expandMapping

function expandMapping(bytes encoding, uint256 cursor, uint8 shortCount) internal view returns (bytes[2][] decodedMapping)

Parses a CBOR-encoded mapping into a 2d-array of bytes.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping starts (in bytes)
shortCountuint8short data identifier included in field info
NameTypeDescription
decodedMappingbytes[2][]the mapping decoded

expandArray

function expandArray(bytes encoding, uint256 cursor, uint8 shortCount) internal view returns (bytes[] decodedArray)

Parses a CBOR-encoded array into an array of bytes.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where array starts (in bytes)
shortCountuint8short data identifier included in field info
NameTypeDescription
decodedArraybytes[]the array decoded

parseDataStructure

function parseDataStructure(bytes encoding, uint256 cursor, enum CBORSpec.MajorType majorType, uint256 shortCount) internal view returns (uint256 dataStart, uint256 dataEnd)

Returns the number of items (not pairs) and where values start/end.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping data starts (in bytes)
majorTypeenum CBORSpec.MajorTypethe corresponding major type identifier
shortCountuint256short data identifier included in field info
NameTypeDescription
dataStartuint256the position where the values for the structure begin.
dataEnduint256the position where the values for the structure end.

getDataStructureItemLength

function getDataStructureItemLength(bytes encoding, uint256 cursor, enum CBORSpec.MajorType majorType, uint256 shortCount) internal view returns (uint256 totalItems, uint256 dataStart, uint256 dataEnd)

Use `parseDataStructure` instead. This is for internal usage. Please take care when using `dataEnd`! This value is ONLY set if the data structure uses an indefinite amount of items, optimizing the efficiency when doing an initial scan to allocate arrays. If the value is not 0, the value can be relied on.

Returns the number of items (not pairs) in a data structure.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping starts (in bytes)
majorTypeenum CBORSpec.MajorTypethe corresponding major type identifier
shortCountuint256short data identifier included in field info
NameTypeDescription
totalItemsuint256the number of total items in the data structure
dataStartuint256the position where the values for the structure begin.
dataEnduint256the position where the values for the structure end.

CBORDataStructures

Solidity library built for decoding CBOR data.

expandMapping

function expandMapping(bytes encoding, uint256 cursor, uint8 shortCount) internal view returns (bytes[2][] decodedMapping)

Parses a CBOR-encoded mapping into a 2d-array of bytes.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping starts (in bytes)
shortCountuint8short data identifier included in field info
NameTypeDescription
decodedMappingbytes[2][]the mapping decoded

expandArray

function expandArray(bytes encoding, uint256 cursor, uint8 shortCount) internal view returns (bytes[] decodedArray)

Parses a CBOR-encoded array into an array of bytes.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where array starts (in bytes)
shortCountuint8short data identifier included in field info
NameTypeDescription
decodedArraybytes[]the array decoded

parseDataStructure

function parseDataStructure(bytes encoding, uint256 cursor, enum CBORSpec.MajorType majorType, uint256 shortCount) internal view returns (uint256 dataStart, uint256 dataEnd)

Returns the number of items (not pairs) and where values start/end.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping data starts (in bytes)
majorTypeenum CBORSpec.MajorTypethe corresponding major type identifier
shortCountuint256short data identifier included in field info
NameTypeDescription
dataStartuint256the position where the values for the structure begin.
dataEnduint256the position where the values for the structure end.

getDataStructureItemLength

function getDataStructureItemLength(bytes encoding, uint256 cursor, enum CBORSpec.MajorType majorType, uint256 shortCount) internal view returns (uint256 totalItems, uint256 dataStart, uint256 dataEnd)

Use `parseDataStructure` instead. This is for internal usage. Please take care when using `dataEnd`! This value is ONLY set if the data structure uses an indefinite amount of items, optimizing the efficiency when doing an initial scan to allocate arrays. If the value is not 0, the value can be relied on.

Returns the number of items (not pairs) in a data structure.

NameTypeDescription
encodingbytesthe dynamic bytes array to scan
cursoruint256position where mapping starts (in bytes)
majorTypeenum CBORSpec.MajorTypethe corresponding major type identifier
shortCountuint256short data identifier included in field info
NameTypeDescription
totalItemsuint256the number of total items in the data structure
dataStartuint256the position where the values for the structure begin.
dataEnduint256the position where the values for the structure end.