Documentation ¶
Overview ¶
Package bsonoptions defines the optional configurations for the BSON codecs.
Index ¶
- type ByteSliceCodecOptions
- type EmptyInterfaceCodecOptions
- type MapCodecOptions
- type SliceCodecOptions
- type StringCodecOptions
- type StructCodecOptions
- func (t *StructCodecOptions) SetAllowUnexportedFields(b bool) *StructCodecOptions
- func (t *StructCodecOptions) SetDecodeDeepZeroInline(b bool) *StructCodecOptions
- func (t *StructCodecOptions) SetDecodeZeroStruct(b bool) *StructCodecOptions
- func (t *StructCodecOptions) SetEncodeOmitDefaultStruct(b bool) *StructCodecOptions
- func (t *StructCodecOptions) SetOverwriteDuplicatedInlinedFields(b bool) *StructCodecOptions
- type TimeCodecOptions
- type UIntCodecOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteSliceCodecOptions ¶ added in v1.3.0
type ByteSliceCodecOptions struct {
EncodeNilAsEmpty *bool // Specifies if a nil byte slice should encode as an empty binary instead of null. Defaults to false.
}
ByteSliceCodecOptions represents all possible options for byte slice encoding and decoding.
func ByteSliceCodec ¶ added in v1.3.0
func ByteSliceCodec() *ByteSliceCodecOptions
ByteSliceCodec creates a new *ByteSliceCodecOptions
func MergeByteSliceCodecOptions ¶ added in v1.3.0
func MergeByteSliceCodecOptions(opts ...*ByteSliceCodecOptions) *ByteSliceCodecOptions
MergeByteSliceCodecOptions combines the given *ByteSliceCodecOptions into a single *ByteSliceCodecOptions in a last one wins fashion.
func (*ByteSliceCodecOptions) SetEncodeNilAsEmpty ¶ added in v1.3.0
func (bs *ByteSliceCodecOptions) SetEncodeNilAsEmpty(b bool) *ByteSliceCodecOptions
SetEncodeNilAsEmpty specifies if a nil byte slice should encode as an empty binary instead of null. Defaults to false.
type EmptyInterfaceCodecOptions ¶ added in v1.3.0
type EmptyInterfaceCodecOptions struct {
DecodeBinaryAsSlice *bool // Specifies if Old and Generic type binarys should default to []slice instead of primitive.Binary. Defaults to false.
}
EmptyInterfaceCodecOptions represents all possible options for interface{} encoding and decoding.
func EmptyInterfaceCodec ¶ added in v1.3.0
func EmptyInterfaceCodec() *EmptyInterfaceCodecOptions
EmptyInterfaceCodec creates a new *EmptyInterfaceCodecOptions
func MergeEmptyInterfaceCodecOptions ¶ added in v1.3.0
func MergeEmptyInterfaceCodecOptions(opts ...*EmptyInterfaceCodecOptions) *EmptyInterfaceCodecOptions
MergeEmptyInterfaceCodecOptions combines the given *EmptyInterfaceCodecOptions into a single *EmptyInterfaceCodecOptions in a last one wins fashion.
func (*EmptyInterfaceCodecOptions) SetDecodeBinaryAsSlice ¶ added in v1.3.0
func (e *EmptyInterfaceCodecOptions) SetDecodeBinaryAsSlice(b bool) *EmptyInterfaceCodecOptions
SetDecodeBinaryAsSlice specifies if Old and Generic type binarys should default to []slice instead of primitive.Binary. Defaults to false.
type MapCodecOptions ¶
type MapCodecOptions struct { DecodeZerosMap *bool // Specifies if the map should be zeroed before decoding into it. Defaults to false. EncodeNilAsEmpty *bool // Specifies if a nil map should encode as an empty document instead of null. Defaults to false. // Specifies how keys should be handled. If false, the behavior matches encoding/json, where the encoding key type must // either be a string, an integer type, or implement bsoncodec.KeyMarshaler and the decoding key type must either be a // string, an integer type, or implement bsoncodec.KeyUnmarshaler. If true, keys are encoded with fmt.Sprint() and the // encoding key type must be a string, an integer type, or a float. If true, the use of Stringer will override // TextMarshaler/TextUnmarshaler. Defaults to false. EncodeKeysWithStringer *bool }
MapCodecOptions represents all possible options for map encoding and decoding.
func MergeMapCodecOptions ¶
func MergeMapCodecOptions(opts ...*MapCodecOptions) *MapCodecOptions
MergeMapCodecOptions combines the given *MapCodecOptions into a single *MapCodecOptions in a last one wins fashion.
func (*MapCodecOptions) SetDecodeZerosMap ¶
func (t *MapCodecOptions) SetDecodeZerosMap(b bool) *MapCodecOptions
SetDecodeZerosMap specifies if the map should be zeroed before decoding into it. Defaults to false.
func (*MapCodecOptions) SetEncodeKeysWithStringer ¶ added in v1.4.0
func (t *MapCodecOptions) SetEncodeKeysWithStringer(b bool) *MapCodecOptions
SetEncodeKeysWithStringer specifies how keys should be handled. If false, the behavior matches encoding/json, where the encoding key type must either be a string, an integer type, or implement bsoncodec.KeyMarshaler and the decoding key type must either be a string, an integer type, or implement bsoncodec.KeyUnmarshaler. If true, keys are encoded with fmt.Sprint() and the encoding key type must be a string, an integer type, or a float. If true, the use of Stringer will override TextMarshaler/TextUnmarshaler. Defaults to false.
func (*MapCodecOptions) SetEncodeNilAsEmpty ¶ added in v1.3.0
func (t *MapCodecOptions) SetEncodeNilAsEmpty(b bool) *MapCodecOptions
SetEncodeNilAsEmpty specifies if a nil map should encode as an empty document instead of null. Defaults to false.
type SliceCodecOptions ¶ added in v1.3.0
type SliceCodecOptions struct {
EncodeNilAsEmpty *bool // Specifies if a nil slice should encode as an empty array instead of null. Defaults to false.
}
SliceCodecOptions represents all possible options for slice encoding and decoding.
func MergeSliceCodecOptions ¶ added in v1.3.0
func MergeSliceCodecOptions(opts ...*SliceCodecOptions) *SliceCodecOptions
MergeSliceCodecOptions combines the given *SliceCodecOptions into a single *SliceCodecOptions in a last one wins fashion.
func SliceCodec ¶ added in v1.3.0
func SliceCodec() *SliceCodecOptions
SliceCodec creates a new *SliceCodecOptions
func (*SliceCodecOptions) SetEncodeNilAsEmpty ¶ added in v1.3.0
func (s *SliceCodecOptions) SetEncodeNilAsEmpty(b bool) *SliceCodecOptions
SetEncodeNilAsEmpty specifies if a nil slice should encode as an empty array instead of null. Defaults to false.
type StringCodecOptions ¶
type StringCodecOptions struct {
DecodeObjectIDAsHex *bool // Specifies if we should decode ObjectID as the hex value. Defaults to true.
}
StringCodecOptions represents all possible options for string encoding and decoding.
func MergeStringCodecOptions ¶
func MergeStringCodecOptions(opts ...*StringCodecOptions) *StringCodecOptions
MergeStringCodecOptions combines the given *StringCodecOptions into a single *StringCodecOptions in a last one wins fashion.
func StringCodec ¶
func StringCodec() *StringCodecOptions
StringCodec creates a new *StringCodecOptions
func (*StringCodecOptions) SetDecodeObjectIDAsHex ¶
func (t *StringCodecOptions) SetDecodeObjectIDAsHex(b bool) *StringCodecOptions
SetDecodeObjectIDAsHex specifies if object IDs should be decoded as their hex representation. If false, a string made from the raw object ID bytes will be used. Defaults to true.
type StructCodecOptions ¶
type StructCodecOptions struct { DecodeZeroStruct *bool // Specifies if structs should be zeroed before decoding into them. Defaults to false. DecodeDeepZeroInline *bool // Specifies if structs should be recursively zeroed when a inline value is decoded. Defaults to false. EncodeOmitDefaultStruct *bool // Specifies if default structs should be considered empty by omitempty. Defaults to false. AllowUnexportedFields *bool // Specifies if unexported fields should be marshaled/unmarshaled. Defaults to false. OverwriteDuplicatedInlinedFields *bool // Specifies if fields in inlined structs can be overwritten by higher level struct fields with the same key. Defaults to true. }
StructCodecOptions represents all possible options for struct encoding and decoding.
func MergeStructCodecOptions ¶
func MergeStructCodecOptions(opts ...*StructCodecOptions) *StructCodecOptions
MergeStructCodecOptions combines the given *StructCodecOptions into a single *StructCodecOptions in a last one wins fashion.
func StructCodec ¶
func StructCodec() *StructCodecOptions
StructCodec creates a new *StructCodecOptions
func (*StructCodecOptions) SetAllowUnexportedFields ¶
func (t *StructCodecOptions) SetAllowUnexportedFields(b bool) *StructCodecOptions
SetAllowUnexportedFields specifies if unexported fields should be marshaled/unmarshaled. Defaults to false.
func (*StructCodecOptions) SetDecodeDeepZeroInline ¶
func (t *StructCodecOptions) SetDecodeDeepZeroInline(b bool) *StructCodecOptions
SetDecodeDeepZeroInline specifies if structs should be zeroed before decoding into them. Defaults to false.
func (*StructCodecOptions) SetDecodeZeroStruct ¶
func (t *StructCodecOptions) SetDecodeZeroStruct(b bool) *StructCodecOptions
SetDecodeZeroStruct specifies if structs should be zeroed before decoding into them. Defaults to false.
func (*StructCodecOptions) SetEncodeOmitDefaultStruct ¶
func (t *StructCodecOptions) SetEncodeOmitDefaultStruct(b bool) *StructCodecOptions
SetEncodeOmitDefaultStruct specifies if default structs should be considered empty by omitempty. A default struct has all its values set to their default value. Defaults to false.
func (*StructCodecOptions) SetOverwriteDuplicatedInlinedFields ¶ added in v1.4.4
func (t *StructCodecOptions) SetOverwriteDuplicatedInlinedFields(b bool) *StructCodecOptions
SetOverwriteDuplicatedInlinedFields specifies if inlined struct fields can be overwritten by higher level struct fields with the same bson key. When true and decoding, values will be written to the outermost struct with a matching key, and when encoding, keys will have the value of the top-most matching field. When false, decoding and encoding will error if there are duplicate keys after the struct is inlined. Defaults to true.
type TimeCodecOptions ¶
type TimeCodecOptions struct {
UseLocalTimeZone *bool // Specifies if we should decode into the local time zone. Defaults to false.
}
TimeCodecOptions represents all possible options for time.Time encoding and decoding.
func MergeTimeCodecOptions ¶
func MergeTimeCodecOptions(opts ...*TimeCodecOptions) *TimeCodecOptions
MergeTimeCodecOptions combines the given *TimeCodecOptions into a single *TimeCodecOptions in a last one wins fashion.
func (*TimeCodecOptions) SetUseLocalTimeZone ¶
func (t *TimeCodecOptions) SetUseLocalTimeZone(b bool) *TimeCodecOptions
SetUseLocalTimeZone specifies if we should decode into the local time zone. Defaults to false.
type UIntCodecOptions ¶ added in v1.3.0
type UIntCodecOptions struct {
EncodeToMinSize *bool // Specifies if all uints except uint64 should be decoded to minimum size bsontype. Defaults to false.
}
UIntCodecOptions represents all possible options for uint encoding and decoding.
func MergeUIntCodecOptions ¶ added in v1.3.0
func MergeUIntCodecOptions(opts ...*UIntCodecOptions) *UIntCodecOptions
MergeUIntCodecOptions combines the given *UIntCodecOptions into a single *UIntCodecOptions in a last one wins fashion.
func UIntCodec ¶ added in v1.3.0
func UIntCodec() *UIntCodecOptions
UIntCodec creates a new *UIntCodecOptions
func (*UIntCodecOptions) SetEncodeToMinSize ¶ added in v1.3.0
func (u *UIntCodecOptions) SetEncodeToMinSize(b bool) *UIntCodecOptions
SetEncodeToMinSize specifies if all uints except uint64 should be decoded to minimum size bsontype. Defaults to false.