modes

package
v0.31.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decode cbor.DecMode = func() cbor.DecMode {
	decode, err := cbor.DecOptions{

		DupMapKey: cbor.DupMapKeyEnforcedAPF,

		TimeTag: cbor.DecTagOptional,

		MaxNestedLevels: 64,

		MaxArrayElements: 1024,
		MaxMapPairs:      1024,

		IndefLength: cbor.IndefLengthAllowed,

		TagsMd: cbor.TagsAllowed,

		IntDec: cbor.IntDecConvertSignedOrFail,

		MapKeyByteString: cbor.MapKeyByteStringForbidden,

		ExtraReturnErrors: cbor.ExtraDecErrorUnknownField,

		DefaultMapType: reflect.TypeOf(map[string]interface{}(nil)),

		UTF8: cbor.UTF8RejectInvalid,

		FieldNameMatching: cbor.FieldNameMatchingCaseSensitive,

		DefaultByteStringType: reflect.TypeOf(""),

		ByteStringToString: cbor.ByteStringToStringAllowedWithExpectedLaterEncoding,

		FieldNameByteString: cbor.FieldNameByteStringAllowed,

		UnrecognizedTagToAny: cbor.UnrecognizedTagContentToAny,

		TimeTagToAny: cbor.TimeTagToRFC3339Nano,

		ByteStringToTime: cbor.ByteStringToTimeAllowed,

		NaN: cbor.NaNDecodeForbidden,
		Inf: cbor.InfDecodeForbidden,

		ByteStringExpectedFormat: cbor.ByteStringExpectedBase64,

		BignumTag: cbor.BignumTagForbidden,

		SimpleValues: simpleValues,

		BinaryUnmarshaler: cbor.BinaryUnmarshalerNone,
	}.DecMode()
	if err != nil {
		panic(err)
	}
	return decode
}()
View Source
var DecodeLax cbor.DecMode = func() cbor.DecMode {
	opts := Decode.DecOptions()
	opts.ExtraReturnErrors &^= cbor.ExtraDecErrorUnknownField
	dm, err := opts.DecMode()
	if err != nil {
		panic(err)
	}
	return dm
}()

DecodeLax is derived from Decode, but does not complain about unknown fields in the input.

View Source
var Diagnostic cbor.DiagMode = func() cbor.DiagMode {
	opts := Decode.DecOptions()
	diagnostic, err := cbor.DiagOptions{
		ByteStringText: true,

		MaxNestedLevels:  opts.MaxNestedLevels,
		MaxArrayElements: opts.MaxArrayElements,
		MaxMapPairs:      opts.MaxMapPairs,
	}.DiagMode()
	if err != nil {
		panic(err)
	}
	return diagnostic
}()
View Source
var Encode = EncMode{
	// contains filtered or unexported fields
}
View Source
var EncodeNondeterministic = EncMode{
	// contains filtered or unexported fields
}

Functions

func RejectCustomMarshalers added in v0.31.0

func RejectCustomMarshalers(v interface{}) error

Returns a non-nil error if and only if the argument's type (or one of its component types, for composite types) implements json.Marshaler or encoding.TextMarshaler without also implementing cbor.Marshaler and likewise for the respective Unmarshaler interfaces.

This is a temporary, graduation-blocking restriction and will be removed in favor of automatic transcoding between CBOR and JSON/text for these types. This restriction allows CBOR to be exercised for in-tree and unstructured types while mitigating the risk of mangling out-of-tree types in client programs.

Types

type BufferProvider added in v0.31.0

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

func (*BufferProvider) Get added in v0.31.0

func (b *BufferProvider) Get() *buffer

func (*BufferProvider) Put added in v0.31.0

func (b *BufferProvider) Put(buf *buffer)

type EncMode added in v0.31.0

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

func (EncMode) Marshal added in v0.31.0

func (em EncMode) Marshal(v interface{}) ([]byte, error)

func (EncMode) MarshalTo added in v0.31.0

func (em EncMode) MarshalTo(v interface{}, w io.Writer) error

Jump to

Keyboard shortcuts

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