// Unmarshal parses the CBOR-encoded data into the value pointed to by v // using default decoding options. If v is nil, not a pointer, or // a nil pointer, Unmarshal returns an error. // // To unmarshal CBOR into a value implementing the Unmarshaler interface, // Unmarshal calls that value's UnmarshalCBOR method with a valid // CBOR value. // // To unmarshal CBOR byte string into a value implementing the // encoding.BinaryUnmarshaler interface, Unmarshal calls that value's // UnmarshalBinary method with decoded CBOR byte string. // // To unmarshal CBOR into a pointer, Unmarshal sets the pointer to nil // if CBOR data is null (0xf6) or undefined (0xf7). Otherwise, Unmarshal // unmarshals CBOR into the value pointed to by the pointer. If the // pointer is nil, Unmarshal creates a new value for it to point to. // // To unmarshal CBOR into an empty interface value, Unmarshal uses the // following rules: // // CBOR booleans decode to bool. // CBOR positive integers decode to uint64. // CBOR negative integers decode to int64 (big.Int if value overflows). // CBOR floating points decode to float64. // CBOR byte strings decode to []byte. // CBOR text strings decode to string. // CBOR arrays decode to []interface{}. // CBOR maps decode to map[interface{}]interface{}. // CBOR null and undefined values decode to nil. // CBOR times (tag 0 and 1) decode to time.Time. // CBOR bignums (tag 2 and 3) decode to big.Int. // CBOR tags with an unrecognized number decode to cbor.Tag // // To unmarshal a CBOR array into a slice, Unmarshal allocates a new slice // if the CBOR array is empty or slice capacity is less than CBOR array length. // Otherwise Unmarshal overwrites existing elements, and sets slice length // to CBOR array length. // // To unmarshal a CBOR array into a Go array, Unmarshal decodes CBOR array // elements into Go array elements. If the Go array is smaller than the // CBOR array, the extra CBOR array elements are discarded. If the CBOR // array is smaller than the Go array, the extra Go array elements are // set to zero values. // // To unmarshal a CBOR array into a struct, struct must have a special field "_" // with struct tag `cbor:",toarray"`. Go array elements are decoded into struct // fields. Any "omitempty" struct field tag option is ignored in this case. // // To unmarshal a CBOR map into a map, Unmarshal allocates a new map only if the // map is nil. Otherwise Unmarshal reuses the existing map and keeps existing // entries. Unmarshal stores key-value pairs from the CBOR map into Go map. // See DecOptions.DupMapKey to enable duplicate map key detection. // // To unmarshal a CBOR map into a struct, Unmarshal matches CBOR map keys to the // keys in the following priority: // // 1. "cbor" key in struct field tag, // 2. "json" key in struct field tag, // 3. struct field name. // // Unmarshal tries an exact match for field name, then a case-insensitive match. // Map key-value pairs without corresponding struct fields are ignored. See // DecOptions.ExtraReturnErrors to return error at unknown field. // // To unmarshal a CBOR text string into a time.Time value, Unmarshal parses text // string formatted in RFC3339. To unmarshal a CBOR integer/float into a // time.Time value, Unmarshal creates an unix time with integer/float as seconds // and fractional seconds since January 1, 1970 UTC. As a special case, Infinite // and NaN float values decode to time.Time's zero value. // // To unmarshal CBOR null (0xf6) and undefined (0xf7) values into a // slice/map/pointer, Unmarshal sets Go value to nil. Because null is often // used to mean "not present", unmarshalling CBOR null and undefined value // into any other Go type has no effect and returns no error. // // Unmarshal supports CBOR tag 55799 (self-describe CBOR), tag 0 and 1 (time), // and tag 2 and 3 (bignum). // // Unmarshal returns ExtraneousDataError error (without decoding into v) // if there are any remaining bytes following the first valid CBOR data item. // See UnmarshalFirst, if you want to unmarshal only the first // CBOR data item without ExtraneousDataError caused by remaining bytes. func Unmarshal(data []byte, v interface{ … } // UnmarshalFirst parses the first CBOR data item into the value pointed to by v // using default decoding options. Any remaining bytes are returned in rest. // // If v is nil, not a pointer, or a nil pointer, UnmarshalFirst returns an error. // // See the documentation for Unmarshal for details. func UnmarshalFirst(data []byte, v interface{ … } // Valid checks whether data is a well-formed encoded CBOR data item and // that it complies with default restrictions such as MaxNestedLevels, // MaxArrayElements, MaxMapPairs, etc. // // If there are any remaining bytes after the CBOR data item, // an ExtraneousDataError is returned. // // WARNING: Valid doesn't check if encoded CBOR data item is valid (i.e. validity) // and RFC 8949 distinctly defines what is "Valid" and what is "Well-formed". // // Deprecated: Valid is kept for compatibility and should not be used. // Use Wellformed instead because it has a more appropriate name. func Valid(data []byte) error { … } // Wellformed checks whether data is a well-formed encoded CBOR data item and // that it complies with default restrictions such as MaxNestedLevels, // MaxArrayElements, MaxMapPairs, etc. // // If there are any remaining bytes after the CBOR data item, // an ExtraneousDataError is returned. func Wellformed(data []byte) error { … } type Unmarshaler … type InvalidUnmarshalError … func (e *InvalidUnmarshalError) Error() string { … } type UnmarshalTypeError … func (e *UnmarshalTypeError) Error() string { … } type InvalidMapKeyTypeError … func (e *InvalidMapKeyTypeError) Error() string { … } type DupMapKeyError … func (e *DupMapKeyError) Error() string { … } type UnknownFieldError … func (e *UnknownFieldError) Error() string { … } type UnacceptableDataItemError … func (e UnacceptableDataItemError) Error() string { … } type ByteStringExpectedFormatError … func newByteStringExpectedFormatError(expectedFormatOption ByteStringExpectedFormatMode, err error) *ByteStringExpectedFormatError { … } func (e *ByteStringExpectedFormatError) Error() string { … } func (e *ByteStringExpectedFormatError) Unwrap() error { … } type InadmissibleTagContentTypeError … func newInadmissibleTagContentTypeError( tagNum int, expectedTagContentType string, gotTagContentType string, ) *InadmissibleTagContentTypeError { … } func newInadmissibleTagContentTypeErrorf(s string) *InadmissibleTagContentTypeError { … } func (e *InadmissibleTagContentTypeError) Error() string { … } type DupMapKeyMode … const DupMapKeyQuiet … const DupMapKeyEnforcedAPF … const maxDupMapKeyMode … func (dmkm DupMapKeyMode) valid() bool { … } type IndefLengthMode … const IndefLengthAllowed … const IndefLengthForbidden … const maxIndefLengthMode … func (m IndefLengthMode) valid() bool { … } type TagsMode … const TagsAllowed … const TagsForbidden … const maxTagsMode … func (tm TagsMode) valid() bool { … } type IntDecMode … const IntDecConvertNone … const IntDecConvertSigned … const IntDecConvertSignedOrFail … const IntDecConvertSignedOrBigInt … const maxIntDec … func (idm IntDecMode) valid() bool { … } type MapKeyByteStringMode … const MapKeyByteStringAllowed … const MapKeyByteStringForbidden … const maxMapKeyByteStringMode … func (mkbsm MapKeyByteStringMode) valid() bool { … } type ExtraDecErrorCond … const ExtraDecErrorNone … const ExtraDecErrorUnknownField … const maxExtraDecError … func (ec ExtraDecErrorCond) valid() bool { … } type UTF8Mode … const UTF8RejectInvalid … const UTF8DecodeInvalid … const maxUTF8Mode … func (um UTF8Mode) valid() bool { … } type FieldNameMatchingMode … const FieldNameMatchingPreferCaseSensitive … const FieldNameMatchingCaseSensitive … const maxFieldNameMatchingMode … func (fnmm FieldNameMatchingMode) valid() bool { … } type BigIntDecMode … const BigIntDecodeValue … const BigIntDecodePointer … const maxBigIntDecMode … func (bidm BigIntDecMode) valid() bool { … } type ByteStringToStringMode … const ByteStringToStringForbidden … const ByteStringToStringAllowed … const ByteStringToStringAllowedWithExpectedLaterEncoding … const maxByteStringToStringMode … func (bstsm ByteStringToStringMode) valid() bool { … } type FieldNameByteStringMode … const FieldNameByteStringForbidden … const FieldNameByteStringAllowed … const maxFieldNameByteStringMode … func (fnbsm FieldNameByteStringMode) valid() bool { … } type UnrecognizedTagToAnyMode … const UnrecognizedTagNumAndContentToAny … const UnrecognizedTagContentToAny … const maxUnrecognizedTagToAny … func (uttam UnrecognizedTagToAnyMode) valid() bool { … } type TimeTagToAnyMode … const TimeTagToTime … const TimeTagToRFC3339 … const TimeTagToRFC3339Nano … const maxTimeTagToAnyMode … func (tttam TimeTagToAnyMode) valid() bool { … } type SimpleValueRegistry … // WithRejectedSimpleValue registers the given simple value as rejected. If the simple value is // encountered in a CBOR input during unmarshaling, an UnacceptableDataItemError is returned. func WithRejectedSimpleValue(sv SimpleValue) func(*SimpleValueRegistry) error { … } // Creates a new SimpleValueRegistry. The registry state is initialized by executing the provided // functions in order against a registry that is pre-populated with the defaults for all well-formed // simple value numbers. func NewSimpleValueRegistryFromDefaults(fns ...func(*SimpleValueRegistry) error) (*SimpleValueRegistry, error) { … } type NaNMode … const NaNDecodeAllowed … const NaNDecodeForbidden … const maxNaNDecode … func (ndm NaNMode) valid() bool { … } type InfMode … const InfDecodeAllowed … const InfDecodeForbidden … const maxInfDecode … func (idm InfMode) valid() bool { … } type ByteStringToTimeMode … const ByteStringToTimeForbidden … const ByteStringToTimeAllowed … const maxByteStringToTimeMode … func (bttm ByteStringToTimeMode) valid() bool { … } type ByteStringExpectedFormatMode … const ByteStringExpectedFormatNone … const ByteStringExpectedBase64URL … const ByteStringExpectedBase64 … const ByteStringExpectedBase16 … const maxByteStringExpectedFormatMode … func (bsefm ByteStringExpectedFormatMode) valid() bool { … } type BignumTagMode … const BignumTagAllowed … const BignumTagForbidden … const maxBignumTag … func (btm BignumTagMode) valid() bool { … } type BinaryUnmarshalerMode … const BinaryUnmarshalerByteString … const BinaryUnmarshalerNone … const maxBinaryUnmarshalerMode … func (bum BinaryUnmarshalerMode) valid() bool { … } type DecOptions … // DecMode returns DecMode with immutable options and no tags (safe for concurrency). func (opts DecOptions) DecMode() (DecMode, error) { … } // validForTags checks that the provided tag set is compatible with these options and returns a // non-nil error if and only if the provided tag set is incompatible. func (opts DecOptions) validForTags(tags TagSet) error { … } // DecModeWithTags returns DecMode with options and tags that are both immutable (safe for concurrency). func (opts DecOptions) DecModeWithTags(tags TagSet) (DecMode, error) { … } // DecModeWithSharedTags returns DecMode with immutable options and mutable shared tags (safe for concurrency). func (opts DecOptions) DecModeWithSharedTags(tags TagSet) (DecMode, error) { … } const defaultMaxArrayElements … const minMaxArrayElements … const maxMaxArrayElements … const defaultMaxMapPairs … const minMaxMapPairs … const maxMaxMapPairs … const defaultMaxNestedLevels … const minMaxNestedLevels … const maxMaxNestedLevels … var defaultSimpleValues … //nolint:gocyclo // Each option comes with some manageable boilerplate func (opts DecOptions) decMode() (*decMode, error) { … } type DecMode … type decMode … var ( defaultDecMode … _ … ) // DecOptions returns user specified options used to create this DecMode. func (dm *decMode) DecOptions() DecOptions { … } // Unmarshal parses the CBOR-encoded data into the value pointed to by v // using dm decoding mode. If v is nil, not a pointer, or a nil pointer, // Unmarshal returns an error. // // See the documentation for Unmarshal for details. func (dm *decMode) Unmarshal(data []byte, v interface{ … } // UnmarshalFirst parses the first CBOR data item into the value pointed to by v // using dm decoding mode. Any remaining bytes are returned in rest. // // If v is nil, not a pointer, or a nil pointer, UnmarshalFirst returns an error. // // See the documentation for Unmarshal for details. func (dm *decMode) UnmarshalFirst(data []byte, v interface{ … } // Valid checks whether data is a well-formed encoded CBOR data item and // that it complies with configurable restrictions such as MaxNestedLevels, // MaxArrayElements, MaxMapPairs, etc. // // If there are any remaining bytes after the CBOR data item, // an ExtraneousDataError is returned. // // WARNING: Valid doesn't check if encoded CBOR data item is valid (i.e. validity) // and RFC 8949 distinctly defines what is "Valid" and what is "Well-formed". // // Deprecated: Valid is kept for compatibility and should not be used. // Use Wellformed instead because it has a more appropriate name. func (dm *decMode) Valid(data []byte) error { … } // Wellformed checks whether data is a well-formed encoded CBOR data item and // that it complies with configurable restrictions such as MaxNestedLevels, // MaxArrayElements, MaxMapPairs, etc. // // If there are any remaining bytes after the CBOR data item, // an ExtraneousDataError is returned. func (dm *decMode) Wellformed(data []byte) error { … } // NewDecoder returns a new decoder that reads from r using dm DecMode. func (dm *decMode) NewDecoder(r io.Reader) *Decoder { … } type decoder … // value decodes CBOR data item into the value pointed to by v. // If CBOR data item fails to be decoded into v, // error is returned and offset is moved to the next CBOR data item. // Precondition: d.data contains at least one well-formed CBOR data item. func (d *decoder) value(v interface{ … } // parseToValue decodes CBOR data to value. It assumes data is well-formed, // and does not perform bounds checking. func (d *decoder) parseToValue(v reflect.Value, tInfo *typeInfo) error { … } func (d *decoder) parseToTag(v reflect.Value) error { … } // parseToTime decodes the current data item as a time.Time. The bool return value is false if and // only if the destination value should remain unmodified. func (d *decoder) parseToTime() (time.Time, bool, error) { … } // parseToUnmarshaler parses CBOR data to value implementing Unmarshaler interface. // It assumes data is well-formed, and does not perform bounds checking. func (d *decoder) parseToUnmarshaler(v reflect.Value) error { … } // parse parses CBOR data and returns value in default Go type. // It assumes data is well-formed, and does not perform bounds checking. func (d *decoder) parse(skipSelfDescribedTag bool) (interface{ … } // parseByteString parses a CBOR encoded byte string. The returned byte slice // may be backed directly by the input. The second return value will be true if // and only if the slice is backed by a copy of the input. Callers are // responsible for making a copy if necessary. func (d *decoder) parseByteString() ([]byte, bool) { … } // applyByteStringTextConversion converts bytes read from a byte string to or from a configured text // encoding. If no transformation was performed (because it was not required), the original byte // slice is returned and the bool return value is false. Otherwise, a new slice containing the // converted bytes is returned along with the bool value true. func (d *decoder) applyByteStringTextConversion( src []byte, dstType reflect.Type, ) ( dst []byte, transformed bool, err error, ) { … } // parseTextString parses CBOR encoded text string. It returns a byte slice // to prevent creating an extra copy of string. Caller should wrap returned // byte slice as string when needed. func (d *decoder) parseTextString() ([]byte, error) { … } func (d *decoder) parseArray() ([]interface{ … } func (d *decoder) parseArrayToSlice(v reflect.Value, tInfo *typeInfo) error { … } func (d *decoder) parseArrayToArray(v reflect.Value, tInfo *typeInfo) error { … } func (d *decoder) parseMap() (interface{ … } func (d *decoder) parseMapToMap(v reflect.Value, tInfo *typeInfo) error { … } func (d *decoder) parseArrayToStruct(v reflect.Value, tInfo *typeInfo) error { … } // parseMapToStruct needs to be fast so gocyclo can be ignored for now. func (d *decoder) parseMapToStruct(v reflect.Value, tInfo *typeInfo) error { … } // validRegisteredTagNums verifies that tag numbers match registered tag numbers of type t. // validRegisteredTagNums assumes next CBOR data type is tag. It scans all tag numbers, and stops at tag content. func (d *decoder) validRegisteredTagNums(registeredTag *tagItem) error { … } func (d *decoder) getRegisteredTagItem(vt reflect.Type) *tagItem { … } // skip moves data offset to the next item. skip assumes data is well-formed, // and does not perform bounds checking. func (d *decoder) skip() { … } func (d *decoder) getHeadWithIndefiniteLengthFlag() ( t cborType, ai byte, val uint64, indefiniteLength bool, ) { … } // getHead assumes data is well-formed, and does not perform bounds checking. func (d *decoder) getHead() (t cborType, ai byte, val uint64) { … } func (d *decoder) numOfItemsUntilBreak() int { … } // foundBreak returns true if next byte is CBOR break code and moves cursor by 1, // otherwise it returns false. // foundBreak assumes data is well-formed, and does not perform bounds checking. func (d *decoder) foundBreak() bool { … } func (d *decoder) reset(data []byte) { … } func (d *decoder) nextCBORType() cborType { … } func (d *decoder) nextCBORNil() bool { … } var typeIntf … var typeTime … var typeBigInt … var typeUnmarshaler … var typeBinaryUnmarshaler … var typeString … var typeByteSlice … func fillNil(_ cborType, v reflect.Value) error { … } func fillPositiveInt(t cborType, val uint64, v reflect.Value) error { … } func fillNegativeInt(t cborType, val int64, v reflect.Value) error { … } func fillBool(t cborType, val bool, v reflect.Value) error { … } func fillFloat(t cborType, val float64, v reflect.Value) error { … } func fillByteString(t cborType, val []byte, shared bool, v reflect.Value, bsts ByteStringToStringMode, bum BinaryUnmarshalerMode) error { … } func fillTextString(t cborType, val []byte, v reflect.Value) error { … } func isImmutableKind(k reflect.Kind) bool { … } func isHashableValue(rv reflect.Value) bool { … } // convertByteSliceToByteString converts []byte to ByteString if // - v is []byte type, or // - v is Tag type and tag content type is []byte // This function also handles nested tags. // CBOR data is already verified to be well-formed before this function is used, // so the recursion won't exceed max nested levels. func convertByteSliceToByteString(v interface{ … }