Documentation
¶
Index ¶
- Variables
- func BuildDefaultRegistry()
- func BuildRegistry() *bsoncodec.Registry
- 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 Registrar
- type Typed
- type TypedGenericCodex
- func (t *TypedGenericCodex) DecodeValue(ctx bsoncodec.DecodeContext, reader bsonrw.ValueReader, value reflect.Value) error
- func (t *TypedGenericCodex) EncodeValue(ctx bsoncodec.EncodeContext, writer bsonrw.ValueWriter, value reflect.Value) error
- func (t *TypedGenericCodex) LookupType(typeName string) (func() Typed, bool)
- func (t *TypedGenericCodex) Register(builder *bsoncodec.RegistryBuilder)
- func (t *TypedGenericCodex) RegisterType(factory func() Typed)
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 Registrar ¶ added in v0.34.0
type Registrar interface {
Register(builder *bsoncodec.RegistryBuilder)
}
type Typed ¶ added in v0.34.0
type Typed interface {
// T returns the type of the document. Different types should report different values.
T() string
}
Typed is implemented by 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 TypedGenericCodex ¶ added in v0.34.0
type TypedGenericCodex 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 method T() is used to determine the type of the document.
func NewTypedGenericCodex ¶ added in v0.34.0
func NewTypedGenericCodex[Interface Typed]() *TypedGenericCodex
func (*TypedGenericCodex) DecodeValue ¶ added in v0.34.0
func (t *TypedGenericCodex) DecodeValue(ctx bsoncodec.DecodeContext, reader bsonrw.ValueReader, value reflect.Value) error
DecodeValue implements the bsoncodec.ValueDecoder interface
func (*TypedGenericCodex) EncodeValue ¶ added in v0.34.0
func (t *TypedGenericCodex) EncodeValue(ctx bsoncodec.EncodeContext, writer bsonrw.ValueWriter, value reflect.Value) error
EncodeValue implements the bsoncodec.ValueEncoder interface
func (*TypedGenericCodex) LookupType ¶ added in v0.34.0
func (t *TypedGenericCodex) LookupType(typeName string) (func() Typed, bool)
LookupType returns the factory function for a given type name
func (*TypedGenericCodex) Register ¶ added in v0.34.0
func (t *TypedGenericCodex) Register(builder *bsoncodec.RegistryBuilder)
Register implements the bsoncodec.RegistryBuilder interface It allows the decoderEncoder to be registered with a bsoncodec.RegistryBuilder
func (*TypedGenericCodex) RegisterType ¶ added in v0.34.0
func (t *TypedGenericCodex) RegisterType(factory func() Typed)
RegisterType registers a factory function for a given type name