Documentation
¶
Overview ¶
Package cbor implements the CBOR (RFC 8949) subset used by COSE structures: integers, byte strings, text strings, arrays, maps, tags, booleans, null, and undefined. Encoding is deterministic (definite lengths, minimal integer encoding, bytewise-sorted map keys). Decoding is strict: indefinite lengths, floating-point values, extended simple values, duplicate map keys, non-integer and non-string map keys, excessive nesting, and trailing data are rejected.
Index ¶
- Variables
- func Decode(data []byte) (any, error)
- func DecodeFirst(data []byte) (any, []byte, error)
- func DecodeNoCopy(data []byte) (any, error)
- func Encode(value any) ([]byte, error)
- func Marshal(value any) ([]byte, error)
- func MarshalValue(value any) (any, error)
- func Unmarshal(data []byte, target any) error
- func UnmarshalValue(value any, target any) error
- type Tag
- type Undefined
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedValue = errors.New("unsupported value") ErrMalformed = errors.New("malformed data") )
var ( ErrInvalidTarget = errors.New("invalid target") ErrTypeMismatch = errors.New("type mismatch") )
Functions ¶
func Decode ¶
Decode deserializes a single value, rejecting trailing data. Integers are returned as int64, byte strings as []byte, text strings as string, arrays as []any, maps as map[any]any (with int64 or string keys), and tagged data items as Tag.
func DecodeFirst ¶ added in v1.1.0
DecodeFirst is Decode, except trailing data is returned rather than rejected: it deserializes the first value in data and additionally returns the bytes that follow it. Used for formats that embed a CBOR item followed by other data whose start is not known in advance, such as the credential public key within WebAuthn authenticator data.
func DecodeNoCopy ¶
DecodeNoCopy is Decode, except decoded byte strings alias data instead of being copied. The caller must keep data alive and unmodified for as long as the decoded byte strings are in use. The aliasing slices have their capacity capped, so appending to them does not modify data.
func Encode ¶
Encode serializes a value deterministically (RFC 8949, Section 4.2.1). Supported types: nil, Undefined, bool, int, int64, uint64, []byte, string, []any, map[int64]any, map[any]any, and Tag.
func MarshalValue ¶
MarshalValue converts a Go value into the CBOR value model. Struct fields are named via the cborschema, jsonschema, or json tag (in that order of precedence); fields tagged omitempty or omitzero are omitted when zero, and []byte becomes a byte string.
func Unmarshal ¶
Unmarshal decodes data and maps the resulting value into target. See UnmarshalValue.
func UnmarshalValue ¶
UnmarshalValue maps a decoded CBOR value into target, which must be a non-nil pointer. Struct fields are matched by the cborschema, jsonschema, or json tag name (in that order of precedence), falling back to the field name; unknown map keys are ignored.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package schema implements validation of decoded CBOR values (the value model produced by github.com/Motmedel/utils_go/pkg/cbor) against schemas.
|
Package schema implements validation of decoded CBOR values (the value model produced by github.com/Motmedel/utils_go/pkg/cbor) against schemas. |