Case:
I have developed custom codec for Google protobuf wrappers (wrappers.BoolValue, etc.).
See https://godoc.org/github.com/golang/protobuf/ptypes/wrappers for details.
My code is:
type ProtoWrappersValueCodec struct {
}
func (e *ProtoWrappersValueCodec) EncodeValue(ectx bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error
{ ... some code }func (e *ProtoWrappersValueCodec) DecodeValue(ectx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { ... some code }
I provide custom registry when create new client:
rb := bson.NewRegistryBuilder()
cod := &ProtoWrappersValueCodec{}
rb.RegisterCodec(reflect.TypeOf(wrappers.BoolValue{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.BytesValue{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.DoubleValue{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.FloatValue{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.Int32Value{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.Int64Value{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.StringValue{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.UInt32Value{}), cod).
RegisterCodec(reflect.TypeOf(wrappers.UInt64Value{}), cod)
client, err := mongo.NewClientWithOptions("mongodb://localhost:27017",
&options.ClientOptions
)
So InsertOne command works great. BSON Encoder calls custom encoders.
But FindOne ignores custom decoders.
I debug driver and see:
Result cursor registry is set by default registry.
Looks like it is set by server's registry.
Looks like server's registry is default registry.
I don't know why but custom registry I provided to the client is ignored.
Please let me know if you need more details.
Thanks!
- is related to
-
GODRIVER-636 Add documentation on how to set a custom bsoncodec.Registry
- Closed