xbson

package
v0.41.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func BuildRegistry() *bsoncodec.Registry

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 Dump added in v0.35.0

func Dump(t *testing.T, title string, bytes []byte)

func IsAlreadyRegistered added in v0.34.0

func IsAlreadyRegistered(registrar Registrar) bool

IsAlreadyRegistered checks if a Registrar is already registered.

func Register added in v0.34.0

func Register(registrar Registrar)

Register registers a Registrar to the list of registrars. If the Registrar is already registered, it will not be registered again. This function is not thread-safe, and it is typically called from init() functions.

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

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

type GetType[Typed any] func(Typed) string

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

Jump to

Keyboard shortcuts

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