Skip to content

Commit 1806418

Browse files
Divjot Aroraskriptble
authored andcommitted
Document behavior of default struct decoder for maps and slices.
GODRIVER-731 Change-Id: I15ce9d98f737871f6d2b80af413ac3d043b2dd00
1 parent ff4c961 commit 1806418

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

bson/bsoncodec/struct_codec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ func (sc *StructCodec) EncodeValue(r EncodeContext, vw bsonrw.ValueWriter, val r
114114
}
115115

116116
// DecodeValue implements the Codec interface.
117+
// By default, map types in val will not be cleared. If a map has existing key/value pairs, it will be extended with the new ones from vr.
118+
// For slices, the decoder will set the length of the slice to zero and append all elements. The underlying array will not be cleared.
117119
func (sc *StructCodec) DecodeValue(r DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
118120
if !val.CanSet() || val.Kind() != reflect.Struct {
119121
return ValueDecoderError{Name: "StructCodec.DecodeValue", Kinds: []reflect.Kind{reflect.Struct}, Received: val}

0 commit comments

Comments
 (0)