cbor

package
v0.87.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Index

Constants

View Source
const (
	CborTypeByteString uint8 = 0x40
	CborTypeTextString uint8 = 0x60
	CborTypeArray      uint8 = 0x80
	CborTypeMap        uint8 = 0xa0
	CborTypeTag        uint8 = 0xc0

	// Only the top 3 bytes are used to specify the type
	CborTypeMask uint8 = 0xe0

	// Max value able to be stored in a single byte without type prefix
	CborMaxUintSimple uint8 = 0x17
)
View Source
const (
	// Useful tag numbers
	CborTagCbor     = 24
	CborTagRational = 30
	CborTagSet      = 258
	CborTagMap      = 259

	// Tag ranges for "alternatives"
	// https://www.ietf.org/archive/id/draft-bormann-cbor-notable-tags-07.html#name-enumerated-alternative-data
	CborTagAlternative1Min = 121
	CborTagAlternative1Max = 127
	CborTagAlternative2Min = 1280
	CborTagAlternative2Max = 1400
	CborTagAlternative3    = 101
)

Variables

This section is empty.

Functions

func Decode

func Decode(dataBytes []byte, dest interface{}) (int, error)

func DecodeById

func DecodeById(
	cborData []byte,
	idMap map[int]interface{},
) (interface{}, error)

Decode CBOR list data by the leading value of each list item. It expects CBOR data and a map of numbers to object pointers to decode into

func DecodeGeneric

func DecodeGeneric(cborData []byte, dest interface{}) error

DecodeGeneric decodes the specified CBOR into the destination object without using the destination object's UnmarshalCBOR() function

func DecodeIdFromList

func DecodeIdFromList(cborData []byte) (int, error)

Extract the first item from a CBOR list. This will return the first item from the provided list if it's numeric and an error otherwise

func Encode

func Encode(data interface{}) ([]byte, error)

func EncodeGeneric added in v0.42.0

func EncodeGeneric(src interface{}) ([]byte, error)

EncodeGeneric encodes the specified object to CBOR without using the source object's MarshalCBOR() function

func ListLength

func ListLength(cborData []byte) (int, error)

Determine the length of a CBOR list

Types

type ByteString

type ByteString struct {
	_cbor.ByteString
}

Wrapper for bytestrings that allows them to be used as keys for a map This was originally a full implementation, but now it just extends the upstream type

func NewByteString

func NewByteString(data []byte) ByteString

func (ByteString) String

func (bs ByteString) String() string

String returns a hex-encoded representation of the bytestring

type Constructor added in v0.46.0

type Constructor struct {
	DecodeStoreCbor
	// contains filtered or unexported fields
}

func NewConstructor added in v0.64.0

func NewConstructor(constructor uint, value any) Constructor

func (Constructor) Constructor added in v0.48.0

func (v Constructor) Constructor() uint

func (Constructor) Fields added in v0.48.0

func (v Constructor) Fields() []any

func (Constructor) FieldsCbor added in v0.64.0

func (c Constructor) FieldsCbor() []byte

func (Constructor) MarshalCBOR added in v0.64.0

func (c Constructor) MarshalCBOR() ([]byte, error)

func (Constructor) MarshalJSON added in v0.46.0

func (v Constructor) MarshalJSON() ([]byte, error)

func (*Constructor) UnmarshalCBOR added in v0.64.0

func (c *Constructor) UnmarshalCBOR(data []byte) error

type DecodeStoreCbor

type DecodeStoreCbor struct {
	// contains filtered or unexported fields
}

func (*DecodeStoreCbor) Cbor

func (d *DecodeStoreCbor) Cbor() []byte

Cbor returns the original CBOR for the object

func (*DecodeStoreCbor) SetCbor added in v0.56.0

func (d *DecodeStoreCbor) SetCbor(cborData []byte)

func (*DecodeStoreCbor) UnmarshalCbor

func (d *DecodeStoreCbor) UnmarshalCbor(
	cborData []byte,
	dest DecodeStoreCborInterface,
) error

UnmarshalCbor decodes the specified CBOR into the destination object and saves the original CBOR

type DecodeStoreCborInterface

type DecodeStoreCborInterface interface {
	Cbor() []byte
	SetCbor([]byte)
}

type IndefLengthList added in v0.53.0

type IndefLengthList struct {
	Items []any
}

func (*IndefLengthList) MarshalCBOR added in v0.53.0

func (i *IndefLengthList) MarshalCBOR() ([]byte, error)

type LazyValue added in v0.46.0

type LazyValue struct {
	// contains filtered or unexported fields
}

func (*LazyValue) Cbor added in v0.46.0

func (l *LazyValue) Cbor() []byte

func (*LazyValue) Decode added in v0.46.0

func (l *LazyValue) Decode() (interface{}, error)

func (*LazyValue) MarshalJSON added in v0.46.0

func (l *LazyValue) MarshalJSON() ([]byte, error)

func (*LazyValue) UnmarshalCBOR added in v0.46.0

func (l *LazyValue) UnmarshalCBOR(data []byte) error

func (*LazyValue) Value added in v0.46.0

func (l *LazyValue) Value() interface{}

type Map added in v0.76.0

type Map map[any]any

Map corresponds to CBOR tag 259 and is used to represent a map with key/value operations

type Rat added in v0.76.0

type Rat struct {
	*big.Rat
}

Rat corresponds to CBOR tag 30 and is used to represent a rational number

func (*Rat) MarshalCBOR added in v0.76.0

func (r *Rat) MarshalCBOR() ([]byte, error)

func (*Rat) ToBigRat added in v0.76.0

func (r *Rat) ToBigRat() *big.Rat

func (*Rat) UnmarshalCBOR added in v0.76.0

func (r *Rat) UnmarshalCBOR(cborData []byte) error

type RawMessage

type RawMessage = _cbor.RawMessage

Create an alias for RawMessage for convenience

type RawTag added in v0.33.4

type RawTag = _cbor.RawTag

type Set added in v0.76.0

type Set []any

Set corresponds to CBOR tag 258 and is used to represent a mathematical finite set

type StructAsArray

type StructAsArray struct {
	// contains filtered or unexported fields
}

Useful for embedding and easier to remember

type Tag

type Tag = _cbor.Tag

Alias for Tag for convenience

type Value

type Value struct {
	// contains filtered or unexported fields
}

Helpful wrapper for parsing arbitrary CBOR data which may contain types that cannot be easily represented in Go (such as maps with bytestring keys)

func (Value) Cbor added in v0.46.0

func (v Value) Cbor() []byte

func (Value) MarshalJSON added in v0.46.0

func (v Value) MarshalJSON() ([]byte, error)

func (*Value) UnmarshalCBOR

func (v *Value) UnmarshalCBOR(data []byte) error

func (Value) Value

func (v Value) Value() interface{}

type WrappedCbor added in v0.76.0

type WrappedCbor []byte

WrappedCbor corresponds to CBOR tag 24 and is used to encode nested CBOR data

func (WrappedCbor) Bytes added in v0.76.0

func (w WrappedCbor) Bytes() []byte

Jump to

Keyboard shortcuts

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