Skip to content

Commit

Permalink
GODRIVER-2866 Update method signatures of bson.ValueMarshaler/`bson…
Browse files Browse the repository at this point in the history
….ValueUnmarshaler` to only use basic types.
  • Loading branch information
qingyang-hu committed Jun 10, 2024
1 parent ab38b74 commit 295cffe
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bson/default_value_decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ func (dvd DefaultValueDecoders) ValueUnmarshalerDecodeValue(_ DecodeContext, vr
// NB: this error should be unreachable due to the above checks
return ValueDecoderError{Name: "ValueUnmarshalerDecodeValue", Types: []reflect.Type{tValueUnmarshaler}, Received: val}
}
return m.UnmarshalBSONValue(t, src)
return m.UnmarshalBSONValue(byte(t), src)
}

// UnmarshalerDecodeValue is the ValueDecoderFunc for Unmarshaler implementations.
Expand Down
2 changes: 1 addition & 1 deletion bson/default_value_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func (dve DefaultValueEncoders) ValueMarshalerEncodeValue(_ EncodeContext, vw Va
if err != nil {
return err
}
return copyValueFromBytes(vw, t, data)
return copyValueFromBytes(vw, Type(t), data)
}

// MarshalerEncodeValue is the ValueEncoderFunc for Marshaler implementations.
Expand Down
2 changes: 1 addition & 1 deletion bson/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Marshaler interface {
// create custom BSON marshaling behavior for an entire BSON document, implement
// the Marshaler interface instead.
type ValueMarshaler interface {
MarshalBSONValue() (Type, []byte, error)
MarshalBSONValue() (byte, []byte, error)
}

// Pool of buffers for marshalling BSON.
Expand Down
6 changes: 3 additions & 3 deletions bson/marshal_value_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ type marshalValueMarshaler struct {

var _ ValueMarshaler = marshalValueMarshaler{}

func (mvi marshalValueMarshaler) MarshalBSONValue() (Type, []byte, error) {
return TypeInt32, bsoncore.AppendInt32(nil, int32(mvi.Foo)), nil
func (mvi marshalValueMarshaler) MarshalBSONValue() (byte, []byte, error) {
return byte(TypeInt32), bsoncore.AppendInt32(nil, int32(mvi.Foo)), nil
}

var _ ValueUnmarshaler = &marshalValueMarshaler{}

func (mvi *marshalValueMarshaler) UnmarshalBSONValue(_ Type, b []byte) error {
func (mvi *marshalValueMarshaler) UnmarshalBSONValue(_ byte, b []byte) error {
v, _, _ := bsoncore.ReadInt32(b)
mvi.Foo = int(v)
return nil
Expand Down
2 changes: 1 addition & 1 deletion bson/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Unmarshaler interface {
// document. To create custom BSON unmarshaling behavior for an entire BSON
// document, implement the Unmarshaler interface instead.
type ValueUnmarshaler interface {
UnmarshalBSONValue(Type, []byte) error
UnmarshalBSONValue(byte, []byte) error
}

// Unmarshal parses the BSON-encoded data and stores the result in the value
Expand Down
4 changes: 2 additions & 2 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func marshalAggregatePipeline(
if err != nil {
return nil, false, err
}
if btype != bson.TypeArray {
return nil, false, fmt.Errorf("ValueMarshaler returned a %v, but was expecting %v", btype, bson.TypeArray)
if typ := bson.Type(btype); typ != bson.TypeArray {
return nil, false, fmt.Errorf("ValueMarshaler returned a %v, but was expecting %v", typ, bson.TypeArray)
}

var hasOutputStage bool
Expand Down
4 changes: 2 additions & 2 deletions mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,6 @@ type bvMarsh struct {
err error
}

func (b bvMarsh) MarshalBSONValue() (bson.Type, []byte, error) {
return b.t, b.data, b.err
func (b bvMarsh) MarshalBSONValue() (byte, []byte, error) {
return byte(b.t), b.data, b.err
}

0 comments on commit 295cffe

Please sign in to comment.