cbor

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CborTagSet is used for sets in Cardano CDDL: set<a> = #6.258([* a])
	CborTagSet = 258

	// CBOR major type 5 (map) encoding constants
	// Maps with 0-23 entries use 0xa0 + length directly
	CborMapBase     = 0xa0 // Base byte for maps with length 0-23
	CborMap1ByteLen = 0xb8 // Map with 1-byte length following (24-255 entries)
	CborMap2ByteLen = 0xb9 // Map with 2-byte length following (256-65535 entries)
	CborMap4ByteLen = 0xba // Map with 4-byte length following (up to ~4 billion)
	CborMap8ByteLen = 0xbb // Map with 8-byte length following (up to ~18 quintillion)
)

CBOR constants used in Cardano

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, dest any) error

Decode decodes CBOR data into the destination object.

func DecodeMapToRaw

func DecodeMapToRaw(data []byte) (map[uint64]RawMessage, error)

DecodeMapToRaw decodes a CBOR map into a map of uint64 keys to raw CBOR bytes. This allows preserving the original CBOR encoding for each field value, which is critical for data containing CBOR tags that may not decode correctly when re-encoded through Go interfaces.

func UnwrapSetTag

func UnwrapSetTag(data []byte) ([]byte, bool, error)

UnwrapSetTag checks if the data is wrapped in a CBOR tag 258 (Set). If it is, it returns the unwrapped content. Otherwise, it returns the original data. The second return value indicates whether the data was wrapped in a Set tag.

Types

type MapPair

type MapPair struct {
	KeyRaw   RawMessage
	ValueRaw RawMessage
}

MapPair represents a key-value pair in a CBOR map where both key and value are preserved as raw CBOR bytes. This is useful for maps that may have complex keys (like CBOR tags) that can't be used as Go map keys.

func DecodeMapPairs

func DecodeMapPairs(data []byte) ([]MapPair, error)

DecodeMapPairs decodes a CBOR map into a slice of key-value pairs, preserving raw bytes for both keys and values. This is essential for handling Plutus data maps where keys can be constructor-tagged values (cbor.Tag) which cannot be used as Go map keys.

type RawMessage

type RawMessage = _cbor.RawMessage

RawMessage is an alias for raw CBOR bytes.

type RawTag

type RawTag = _cbor.RawTag

RawTag is an alias for the fxamacker/cbor RawTag type. It represents a CBOR tag with its number and raw content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL