Documentation ¶
Index ¶
- Variables
- func BuildDefaultRegistry()
- func BuildRegistry() *bsoncodec.Registry
- func Dump(t *testing.T, title string, bytes []byte)
- func IsAlreadyRegistered(registrar Registrar) bool
- func Register(registrar Registrar)
- type BsonCodecsRegistrant
- type BsonRegistryBuilder
- func (b *BsonRegistryBuilder) Build()
- func (b *BsonRegistryBuilder) Register(registrant BsonCodecsRegistrant) *BsonRegistryBuilder
- func (b *BsonRegistryBuilder) RegisterAll(registrants ...BsonCodecsRegistrant) *BsonRegistryBuilder
- func (b *BsonRegistryBuilder) RegisterTypeDecoder(t reflect.Type, dec bsoncodec.ValueDecoder)
- func (b *BsonRegistryBuilder) RegisterTypeEncoder(t reflect.Type, dec bsoncodec.ValueEncoder)
- func (b *BsonRegistryBuilder) StructCodec() *bsoncodec.StructCodec
- type EncoderDecoder
- type GetType
- type Registrar
- type TypedGenericCodex
- func (t *TypedGenericCodex[Typed]) DecodeValue(ctx bsoncodec.DecodeContext, reader bsonrw.ValueReader, value reflect.Value) error
- func (t *TypedGenericCodex[Typed]) EncodeValue(ctx bsoncodec.EncodeContext, writer bsonrw.ValueWriter, value reflect.Value) error
- func (t *TypedGenericCodex[Typed]) Register(builder *bsoncodec.RegistryBuilder)
- func (t *TypedGenericCodex[Typed]) RegisterType(factory func() Typed, toDto func(Typed) interface{}, ...)
Constants ¶
This section is empty.
Variables ¶
var DefaultBsonRegistryBuilder = NewBsonRegistryBuilder()
Functions ¶
func BuildDefaultRegistry ¶ added in v0.34.0
func BuildDefaultRegistry()
BuildDefaultRegistry builds the default registry to be used by the mongo driver Previous registries are discarded
func BuildRegistry ¶ added in v0.34.0
BuildRegistry creates a new registry configured with the default encoders and decoders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types, the PrimitiveCodecs type in this package, and all registered registrars.
func IsAlreadyRegistered ¶ added in v0.34.0
IsAlreadyRegistered checks if a Registrar is already registered.
Types ¶
type BsonCodecsRegistrant ¶
type BsonCodecsRegistrant func(builder *BsonRegistryBuilder)
type BsonRegistryBuilder ¶
type BsonRegistryBuilder struct { *bsoncodec.RegistryBuilder // contains filtered or unexported fields }
BsonRegistryBuilder initializes the mongo driver registry to encode/decode honoring the JSON struct tags. For example, a struct with the following JSON tags:
type Sample struct { FirstName string `json:"first_name"` }
Will serialize the field to BSON as "first_name" instead of "firstname" (default naming strategy).
func NewBsonRegistryBuilder ¶
func NewBsonRegistryBuilder() *BsonRegistryBuilder
func (*BsonRegistryBuilder) Build ¶
func (b *BsonRegistryBuilder) Build()
Build sets this registry as the BSON default
func (*BsonRegistryBuilder) Register ¶
func (b *BsonRegistryBuilder) Register(registrant BsonCodecsRegistrant) *BsonRegistryBuilder
Register a custom codec to the default BSON registry
func (*BsonRegistryBuilder) RegisterAll ¶
func (b *BsonRegistryBuilder) RegisterAll(registrants ...BsonCodecsRegistrant) *BsonRegistryBuilder
RegisterAll register all the custom codecs to the default BSON registry
func (*BsonRegistryBuilder) RegisterTypeDecoder ¶
func (b *BsonRegistryBuilder) RegisterTypeDecoder(t reflect.Type, dec bsoncodec.ValueDecoder)
func (*BsonRegistryBuilder) RegisterTypeEncoder ¶ added in v0.19.1
func (b *BsonRegistryBuilder) RegisterTypeEncoder(t reflect.Type, dec bsoncodec.ValueEncoder)
func (*BsonRegistryBuilder) StructCodec ¶
func (b *BsonRegistryBuilder) StructCodec() *bsoncodec.StructCodec
StructCodec provides the configured bsoncodec.StructCodec in registry
type EncoderDecoder ¶ added in v0.34.0
type EncoderDecoder interface { Registrar bsoncodec.ValueDecoder bsoncodec.ValueEncoder }
EncoderDecoder is a bsoncodec.ValueDecoder and bsoncodec.ValueEncoder for a given type
func NewDecoderEncoder ¶ added in v0.34.0
func NewDecoderEncoder[Entity, Dto, Base any](toDto func(Entity) Dto, fromDto func(Dto) Entity) EncoderDecoder
NewDecoderEncoder creates a new decoderEncoder backed by the provided conversion functions
type GetType ¶ added in v0.36.2
GetType provides the type for a family of types that can be encoded/decoded to/from a bson document. It allows a generic type to be encoded/decoded to/from a bson document.
type Registrar ¶ added in v0.34.0
type Registrar interface {
Register(builder *bsoncodec.RegistryBuilder)
}
type TypedGenericCodex ¶ added in v0.34.0
type TypedGenericCodex[Typed any] struct { // contains filtered or unexported fields }
TypedGenericCodex is a generic encoder/decoder for a family of types that implement the Typed interface It allows a generic type to be encoded/decoded to/from a bson document. The getType function is used to determine the type of the underlying value.
func NewTypedGenericCodex ¶ added in v0.34.0
func NewTypedGenericCodex[Typed any](getType GetType[Typed]) *TypedGenericCodex[Typed]
func (*TypedGenericCodex[Typed]) DecodeValue ¶ added in v0.34.0
func (t *TypedGenericCodex[Typed]) DecodeValue(ctx bsoncodec.DecodeContext, reader bsonrw.ValueReader, value reflect.Value) error
DecodeValue implements the bsoncodec.ValueDecoder interface
func (*TypedGenericCodex[Typed]) EncodeValue ¶ added in v0.34.0
func (t *TypedGenericCodex[Typed]) EncodeValue(ctx bsoncodec.EncodeContext, writer bsonrw.ValueWriter, value reflect.Value) error
EncodeValue implements the bsoncodec.ValueEncoder interface
func (*TypedGenericCodex[Typed]) Register ¶ added in v0.34.0
func (t *TypedGenericCodex[Typed]) Register(builder *bsoncodec.RegistryBuilder)
Register implements the bsoncodec.RegistryBuilder interface It allows the decoderEncoder to be registered with a bsoncodec.RegistryBuilder
func (*TypedGenericCodex[Typed]) RegisterType ¶ added in v0.34.0
func (t *TypedGenericCodex[Typed]) RegisterType( factory func() Typed, toDto func(Typed) interface{}, fromDto func(interface{}) Typed, )
RegisterType registers a factory function for a given type name