Documentation
¶
Index ¶
- Constants
- func Decode(dataBytes []byte, dest interface{}) (int, error)
- func DecodeById(cborData []byte, idMap map[int]interface{}) (interface{}, error)
- func DecodeGeneric(cborData []byte, dest interface{}) error
- func DecodeIdFromList(cborData []byte) (int, error)
- func Encode(data interface{}) ([]byte, error)
- func EncodeGeneric(src interface{}) ([]byte, error)
- func ListLength(cborData []byte) (int, error)
- type ByteString
- type Constructor
- type DecodeStoreCbor
- type DecodeStoreCborInterface
- type LazyValue
- type RawMessage
- type RawTag
- type StructAsArray
- type Tag
- type Value
Constants ¶
const ( CBOR_TYPE_BYTE_STRING uint8 = 0x40 CBOR_TYPE_TEXT_STRING uint8 = 0x60 CBOR_TYPE_ARRAY uint8 = 0x80 CBOR_TYPE_MAP uint8 = 0xa0 CBOR_TYPE_TAG uint8 = 0xc0 // Only the top 3 bytes are used to specify the type CBOR_TYPE_MASK uint8 = 0xe0 // Max value able to be stored in a single byte without type prefix CBOR_MAX_UINT_SIMPLE uint8 = 0x17 // Useful tag numbers CborTagSet = 258 CborTagMap = 259 )
Variables ¶
This section is empty.
Functions ¶
func DecodeById ¶
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 ¶
DecodeGeneric decodes the specified CBOR into the destination object without using the destination object's UnmarshalCBOR() function
func DecodeIdFromList ¶
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 EncodeGeneric ¶ added in v0.42.0
EncodeGeneric encodes the specified object to CBOR without using the source object's MarshalCBOR() function
Types ¶
type ByteString ¶
type ByteString string
Wrapper for bytestrings that allows them to be used as keys for a map We use a string because []byte isn't comparable, which means it can't be used as a map key
func NewByteString ¶
func NewByteString(data []byte) ByteString
func (ByteString) Bytes ¶
func (bs ByteString) Bytes() []byte
func (ByteString) MarshalCBOR ¶ added in v0.42.0
func (bs ByteString) MarshalCBOR() ([]byte, error)
func (ByteString) String ¶
func (bs ByteString) String() string
func (*ByteString) UnmarshalCBOR ¶
func (bs *ByteString) UnmarshalCBOR(data []byte) error
type Constructor ¶ added in v0.46.0
type Constructor struct {
// contains filtered or unexported fields
}
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) MarshalJSON ¶ added in v0.46.0
func (v Constructor) MarshalJSON() ([]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) 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
}
type LazyValue ¶ added in v0.46.0
type LazyValue struct {
// contains filtered or unexported fields
}
func (*LazyValue) MarshalJSON ¶ added in v0.46.0
func (*LazyValue) UnmarshalCBOR ¶ added in v0.46.0
type StructAsArray ¶
type StructAsArray struct {
// contains filtered or unexported fields
}
Useful for embedding and easier to remember
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)