-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GODRIVER-2711 Deprecate BSON *Append and *With functions. #1251
GODRIVER-2711 Deprecate BSON *Append and *With functions. #1251
Conversation
319ae80
to
10a0e19
Compare
10a0e19
to
b58a4c9
Compare
// Extended JSON by converting them to bson.Raw. | ||
for { | ||
doc, err := bson.ReadDocument(buf) | ||
if err == io.EOF { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is necessary to leave a comment on the io.EOF
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good ideal! I'll extend the comment above to mention that ReadDocument
returns io.EOF
when the input is empty.
bson/bsonrw/extjson_writer.go
Outdated
// Always end top-level documents with a newline so that multiple documents can be encoded | ||
// to the same writer. That matches the Go json.Encoder behavior and also works with | ||
// bsonrw.NewExtJSONValueReader. | ||
ejvw.buf = append(ejvw.buf, '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addition causes corpus failures:
go test -run Test_BsonCorpus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! To match the behavior of the Go encoding/json
library, we actually only want to apply this to the output generated by Encode
and not by MarshalExtJSON
. I'm not sure if the BSON corpus tests use Encode
or MarshalExtJSON
, but it's possible that change will resolve the failures. If not, I'll look into whether or not it's a good idea to trim whitespace in the BSON corpus tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to only add newlines when using Encoder.Encode
.
0219392
to
4ade632
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for all of the examples
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
4ade632
to
04f1c97
Compare
GODRIVER-2711
Summary
bson
packageMarshal
/Unmarshal
functions that append data to an existing byte slice. Recommend people use theEncoder
orDecoder
types instead.bson
packageMarshal
/Unmarshal
functions that accept aRegistry
. Recommend people use theEncoder
orDecoder
types instead.EncodeContext
orDecodeContext
during marshaling or unmarshaling. Recommend people use theEncoder
orDecoder
configuration functions instead.Encoder
andDecoder
to achieve most deprecated behaviors.Background & Motivation
The
bson
package is cluttered with permutations of*WithRegistry
,*WithContext
and*Append
functions forMarshal
andUnmarshal
. The same behavior can be now be achieved with anEncoder
orDecoder
, making the*WithRegistry
,*WithContext
, and*Append
functions redundant. Provide examples to show users how to migrate their use cases toEncoder
orDecoder
and deprecate the redundant functions in preparation to remove them in Go Driver 2.0.