Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2612 Remove RegistryBuilder #1659

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions bson/array_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)

// ArrayCodec is the Codec used for bsoncore.Array values.
//
// Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
// ArrayCodec registered.
type ArrayCodec struct{}

var defaultArrayCodec = NewArrayCodec()

// NewArrayCodec returns an ArrayCodec.
//
// Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
// ArrayCodec registered.
func NewArrayCodec() *ArrayCodec {
return &ArrayCodec{}
}
// arrayCodec is the Codec used for bsoncore.Array values.
type arrayCodec struct{}

// EncodeValue is the ValueEncoder for bsoncore.Array values.
func (ac *ArrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
func (ac *arrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
if !val.IsValid() || val.Type() != tCoreArray {
return ValueEncoderError{Name: "CoreArrayEncodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
}
Expand All @@ -39,7 +26,7 @@ func (ac *ArrayCodec) EncodeValue(_ EncodeContext, vw ValueWriter, val reflect.V
}

// DecodeValue is the ValueDecoder for bsoncore.Array values.
func (ac *ArrayCodec) DecodeValue(_ DecodeContext, vr ValueReader, val reflect.Value) error {
func (ac *arrayCodec) DecodeValue(_ DecodeContext, vr ValueReader, val reflect.Value) error {
if !val.CanSet() || val.Type() != tCoreArray {
return ValueDecoderError{Name: "CoreArrayDecodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
}
Expand Down
16 changes: 7 additions & 9 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/mongo-driver/bson/bsonoptions"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
Expand Down Expand Up @@ -349,19 +348,18 @@ func TestMapCodec(t *testing.T) {
strstr := stringerString("foo")
mapObj := map[stringerString]int{strstr: 1}
testCases := []struct {
name string
opts *bsonoptions.MapCodecOptions
key string
name string
mapCodec *mapCodec
key string
}{
{"default", bsonoptions.MapCodec(), "foo"},
{"true", bsonoptions.MapCodec().SetEncodeKeysWithStringer(true), "bar"},
{"false", bsonoptions.MapCodec().SetEncodeKeysWithStringer(false), "foo"},
{"default", &mapCodec{}, "foo"},
{"true", &mapCodec{encodeKeysWithStringer: true}, "bar"},
{"false", &mapCodec{encodeKeysWithStringer: false}, "foo"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mapCodec := NewMapCodec(tc.opts)
mapRegistry := NewRegistry()
mapRegistry.RegisterKindEncoder(reflect.Map, mapCodec)
mapRegistry.RegisterKindEncoder(reflect.Map, tc.mapCodec)
buf := new(bytes.Buffer)
vw := NewValueWriter(buf)
enc := NewEncoder(vw)
Expand Down
2 changes: 1 addition & 1 deletion bson/bsoncodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func ExampleValueEncoder() {
var _ ValueEncoderFunc = func(ec EncodeContext, vw ValueWriter, val reflect.Value) error {
var _ ValueEncoderFunc = func(_ EncodeContext, vw ValueWriter, val reflect.Value) error {
if val.Kind() != reflect.String {
return ValueEncoderError{Name: "StringEncodeValue", Kinds: []reflect.Kind{reflect.String}, Received: val}
}
Expand Down
49 changes: 0 additions & 49 deletions bson/bsonoptions/byte_slice_codec_options.go

This file was deleted.

8 changes: 0 additions & 8 deletions bson/bsonoptions/doc.go

This file was deleted.

49 changes: 0 additions & 49 deletions bson/bsonoptions/empty_interface_codec_options.go

This file was deleted.

82 changes: 0 additions & 82 deletions bson/bsonoptions/map_codec_options.go

This file was deleted.

49 changes: 0 additions & 49 deletions bson/bsonoptions/slice_codec_options.go

This file was deleted.

52 changes: 0 additions & 52 deletions bson/bsonoptions/string_codec_options.go

This file was deleted.

Loading