Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Dec 6, 2023
1 parent 40c94dd commit 6cc5e96
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions bson/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ func MarshalValue(val interface{}) (bsontype.Type, []byte, error) {
// Deprecated: Using a custom registry to marshal individual BSON values will not be supported in Go
// Driver 2.0.
func MarshalValueWithRegistry(r *bsoncodec.Registry, val interface{}) (bsontype.Type, []byte, error) {
sw := new(bsonrw.SliceWriter)
*sw = make([]byte, 0)
vwFlusher := bvwPool.GetAtModeElement(sw)
// sw := new(bsonrw.SliceWriter)
// *sw = make([]byte, 0)
var sw bsonrw.SliceWriter
vwFlusher := bvwPool.GetAtModeElement(&sw)

// get an Encoder and encode the value
enc := encPool.Get().(*Encoder)
Expand All @@ -94,11 +95,11 @@ func MarshalValueWithRegistry(r *bsoncodec.Registry, val interface{}) (bsontype.
// flush the bytes written because we cannot guarantee that a full document has been written
// after the flush, *sw will be in the format
// [value type, 0 (null byte to indicate end of empty element name), value bytes..]
if err := vwFlusher.Flush(); err != nil {
return 0, nil, err
}
buffer := *sw
return bsontype.Type(buffer[0]), buffer[2:], nil
// if err := vwFlusher.Flush(); err != nil {
// return 0, nil, err
// }
// buffer := *sw
return bsontype.Type(sw[0]), sw[2:], nil
}

// MarshalValueWithContext returns the BSON encoding of val using EncodeContext ec.
Expand Down

0 comments on commit 6cc5e96

Please sign in to comment.