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 3c6dfdb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 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 @@ -97,8 +98,8 @@ func MarshalValueWithRegistry(r *bsoncodec.Registry, val interface{}) (bsontype.
if err := vwFlusher.Flush(); err != nil {
return 0, nil, err
}
buffer := *sw
return bsontype.Type(buffer[0]), buffer[2:], nil
// 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 3c6dfdb

Please sign in to comment.