Skip to content

GODRIVER-2612 Merge bsoncodec, bsontype, bsonrw, primitive into bson. #1565

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

Merged
merged 10 commits into from
Apr 17, 2024

Conversation

qingyang-hu
Copy link
Collaborator

@qingyang-hu qingyang-hu commented Feb 16, 2024

GODRIVER-2612 Remove references to the bson packages from the bsoncore.

GODRIVER-2708 Merge the bsoncodec
GODRIVER-2723 Merge the bsontype
GODRIVER-2707, GODRIVER-2710 Merge the bsonrw
GODRIVER-2718 Merge the mgocompat
GODRIVER-2611 Merge the primitive

Summary

  • Merge bsoncodec, bsontype, bsonrw, mgocompat, primitive into the bson.
  • Remove references to the bson packages from the bsoncore to prevent import cycles.
  • Move TypeXXX constants from the bsontype package to the bsoncore package, so importing is unidirectional from the bsoncore.
  • Unexport functions on the Copier type.

Background & Motivation

This PR simplifies the following deprecation in GODRIVER-2612 by avoiding import cycles.
Most functions from bsoncodec will be deprecated in the following PRs.

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Feb 16, 2024

API Change Report

./bson

incompatible changes

##(*Decoder).Reset: changed from func(./bson/bsonrw.ValueReader) to func(ValueReader)
##(Decoder).SetRegistry: changed from func(./bson/bsoncodec.Registry) to func(*Registry)
##(*Encoder).Reset: changed from func(./bson/bsonrw.ValueWriter) to func(ValueWriter)
##(Encoder).SetRegistry: changed from func(./bson/bsoncodec.Registry) to func(*Registry)
##A: changed from ./bson/primitive.A to A
##D: changed from ./bson/primitive.D to D
##DefaultRegistry: changed from *./bson/bsoncodec.Registry to Registry
##E: changed from ./bson/primitive.E to E
##M: changed from ./bson/primitive.M to M
##MarshalValue: changed from func(interface{}) (./bson/bsontype.Type, []byte, error) to func(interface{}) (Type, []byte, error)
##MarshalValueWithRegistry: changed from func(
./bson/bsoncodec.Registry, interface{}) (./bson/bsontype.Type, []byte, error) to func(*Registry, interface{}) (Type, []byte, error)
##NewDecoder: changed from func(./bson/bsonrw.ValueReader) *Decoder to func(ValueReader) *Decoder
##NewEncoder: changed from func(./bson/bsonrw.ValueWriter) *Encoder to func(ValueWriter) *Encoder
##NewRegistry: changed from func() *./bson/bsoncodec.Registry to func() *Registry
##NewRegistryBuilder: changed from func() *./bson/bsoncodec.RegistryBuilder to func() RegistryBuilder
##PrimitiveCodecs.RawDecodeValue: changed from func(./bson/bsoncodec.DecodeContext, ./bson/bsonrw.ValueReader, reflect.Value) error to func(DecodeContext, ValueReader, reflect.Value) error
##PrimitiveCodecs.RawEncodeValue: changed from func(./bson/bsoncodec.EncodeContext, ./bson/bsonrw.ValueWriter, reflect.Value) error to func(EncodeContext, ValueWriter, reflect.Value) error
##PrimitiveCodecs.RawValueDecodeValue: changed from func(./bson/bsoncodec.DecodeContext, ./bson/bsonrw.ValueReader, reflect.Value) error to func(DecodeContext, ValueReader, reflect.Value) error
##PrimitiveCodecs.RawValueEncodeValue: changed from func(./bson/bsoncodec.EncodeContext, ./bson/bsonrw.ValueWriter, reflect.Value) error to func(EncodeContext, ValueWriter, reflect.Value) error
##PrimitiveCodecs.RegisterPrimitiveCodecs: changed from func(
./bson/bsoncodec.RegistryBuilder) to func(RegistryBuilder)
##RawValue.DBPointer: changed from func() (string, ./bson/primitive.ObjectID) to func() (string, ObjectID)
##RawValue.DBPointerOK: changed from func() (string, ./bson/primitive.ObjectID, bool) to func() (string, ObjectID, bool)
##RawValue.Decimal128: changed from func() ./bson/primitive.Decimal128 to func() Decimal128
##RawValue.Decimal128OK: changed from func() (./bson/primitive.Decimal128, bool) to func() (Decimal128, bool)
##RawValue.ObjectID: changed from func() ./bson/primitive.ObjectID to func() ObjectID
##RawValue.ObjectIDOK: changed from func() (./bson/primitive.ObjectID, bool) to func() (ObjectID, bool)
##RawValue.Type: changed from ./bson/bsontype.Type to Type
##RawValue.UnmarshalWithContext: changed from func(
./bson/bsoncodec.DecodeContext, interface{}) error to func(DecodeContext, interface{}) error
##RawValue.UnmarshalWithRegistry: changed from func(
./bson/bsoncodec.Registry, interface{}) error to func(Registry, interface{}) error
##TypeArray: changed from ./bson/bsontype.Type to Type
##TypeBinary: changed from ./bson/bsontype.Type to Type
##TypeBoolean: changed from ./bson/bsontype.Type to Type
##TypeCodeWithScope: changed from ./bson/bsontype.Type to Type
##TypeDBPointer: changed from ./bson/bsontype.Type to Type
##TypeDateTime: changed from ./bson/bsontype.Type to Type
##TypeDecimal128: changed from ./bson/bsontype.Type to Type
##TypeDouble: changed from ./bson/bsontype.Type to Type
##TypeEmbeddedDocument: changed from ./bson/bsontype.Type to Type
##TypeInt32: changed from ./bson/bsontype.Type to Type
##TypeInt64: changed from ./bson/bsontype.Type to Type
##TypeJavaScript: changed from ./bson/bsontype.Type to Type
##TypeMaxKey: changed from ./bson/bsontype.Type to Type
##TypeMinKey: changed from ./bson/bsontype.Type to Type
##TypeNull: changed from ./bson/bsontype.Type to Type
##TypeObjectID: changed from ./bson/bsontype.Type to Type
##TypeRegex: changed from ./bson/bsontype.Type to Type
##TypeString: changed from ./bson/bsontype.Type to Type
##TypeSymbol: changed from ./bson/bsontype.Type to Type
##TypeTimestamp: changed from ./bson/bsontype.Type to Type
##TypeUndefined: changed from ./bson/bsontype.Type to Type
##UnmarshalExtJSONWithContext: changed from func(./bson/bsoncodec.DecodeContext, []byte, bool, interface{}) error to func(DecodeContext, []byte, bool, interface{}) error
##UnmarshalExtJSONWithRegistry: changed from func(
./bson/bsoncodec.Registry, []byte, bool, interface{}) error to func(Registry, []byte, bool, interface{}) error
##UnmarshalValue: changed from func(./bson/bsontype.Type, []byte, interface{}) error to func(Type, []byte, interface{}) error
##UnmarshalValueWithRegistry: changed from func(
./bson/bsoncodec.Registry, ./bson/bsontype.Type, []byte, interface{}) error to func(Registry, Type, []byte, interface{}) error
##UnmarshalWithContext: changed from func(./bson/bsoncodec.DecodeContext, []byte, interface{}) error to func(DecodeContext, []byte, interface{}) error
##UnmarshalWithRegistry: changed from func(
./bson/bsoncodec.Registry, []byte, interface{}) error to func(*Registry, []byte, interface{}) error
##ValueMarshaler.MarshalBSONValue: changed from func() (./bson/bsontype.Type, []byte, error) to func() (Type, []byte, error)
##ValueUnmarshaler.UnmarshalBSONValue: changed from func(./bson/bsontype.Type, []byte) error to func(Type, []byte) error

compatible changes

ArrayCodec: added
ArrayReader: added
ArrayWriter: added
Binary: added
ByteSliceCodec: added
BytesReader: added
BytesWriter: added
CodeWithScope: added
CodecZeroer: added
CompareTimestamp: added
CopyValueToBytes: added
DBPointer: added
DateTime: added
Decimal128: added
DecodeContext: added
DecodeError: added
DefaultStructTagParser: added
DefaultValueDecoders: added
DefaultValueEncoders: added
DocumentReader: added
DocumentWriter: added
EmptyInterfaceCodec: added
EncodeContext: added
ErrEOA: added
ErrEOD: added
ErrInvalidHex: added
ErrInvalidJSON: added
ErrNilType: added
ErrNoDecoder: added
ErrNoEncoder: added
ErrNoTypeMapEntry: added
ErrNotInterface: added
ErrNotPointer: added
ErrParseInf: added
ErrParseNaN: added
ErrParseNegInf: added
ExtJSONValueReaderPool: added
ExtJSONValueWriterPool: added
IsValidObjectID: added
JSONFallbackStructTagParser: added
JavaScript: added
KeyMarshaler: added
KeyUnmarshaler: added
MapCodec: added
MaxDecimal128Exp: added
MaxKey: added
MinDecimal128Exp: added
MinKey: added
NewArrayCodec: added
NewBSONValueReader: added
NewByteSliceCodec: added
NewDateTimeFromTime: added
NewDecimal128: added
NewEmptyInterfaceCodec: added
NewExtJSONValueReader: added
NewExtJSONValueReaderPool: added
NewExtJSONValueWriter: added
NewExtJSONValueWriterPool: added
NewMapCodec: added
NewObjectID: added
NewObjectIDFromTimestamp: added
NewPointerCodec: added
NewSliceCodec: added
NewStringCodec: added
NewStructCodec: added
NewTimeCodec: added
NewUIntCodec: added
NewValueReader: added
NewValueReaderPool: added
NewValueWriter: added
NewValueWriterPool: added
NilObjectID: added
Null: added
ObjectID: added
ObjectIDFromHex: added
ParseDecimal128: added
ParseDecimal128FromBigInt: added
PointerCodec: added
Proxy: added
Regex: added
Registry: added
RegistryBuilder: added
SliceCodec: added
SliceWriter: added
StringCodec: added
StructCodec: added
StructTagParser: added
StructTagParserFunc: added
StructTags: added
Symbol: added
TimeCodec: added
Timestamp: added
TransitionError: added
Type: added
UIntCodec: added
Undefined: added
ValueCodec: added
ValueDecoder: added
ValueDecoderError: added
ValueDecoderFunc: added
ValueEncoder: added
ValueEncoderError: added
ValueEncoderFunc: added
ValueReader: added
ValueReaderPool: added
ValueWriter: added
ValueWriterFlusher: added
ValueWriterPool: added

./bson/bsoncodec

incompatible changes

package removed

./bson/bsonrw

incompatible changes

package removed

./bson/bsonrw/bsonrwtest

incompatible changes

package removed

./bson/bsontype

incompatible changes

package removed

./bson/mgocompat

incompatible changes

##GetterEncodeValue: changed from func(./bson/bsoncodec.EncodeContext, ./bson/bsonrw.ValueWriter, reflect.Value) error to func(./bson.EncodeContext, ./bson.ValueWriter, reflect.Value) error
##NewRegistryBuilder: changed from func() *./bson/bsoncodec.RegistryBuilder to func() *./bson.RegistryBuilder
##NewRespectNilValuesRegistryBuilder: changed from func() *./bson/bsoncodec.RegistryBuilder to func() *./bson.RegistryBuilder
##Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry
RegistryRespectNilValues: removed
##SetterDecodeValue: changed from func(./bson/bsoncodec.DecodeContext, ./bson/bsonrw.ValueReader, reflect.Value) error to func(./bson.DecodeContext, ./bson.ValueReader, reflect.Value) error

compatible changes

RespectNilValuesRegistry: added

./bson/primitive

incompatible changes

package removed

./event

incompatible changes

##CommandFailedEvent.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##CommandFinishedEvent.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##CommandStartedEvent.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##CommandSucceededEvent.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##PoolEvent.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##ServerClosedEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##ServerDescriptionChangedEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##ServerOpeningEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##TopologyClosedEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##TopologyDescriptionChangedEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##TopologyOpeningEvent.TopologyID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID

./mongo

incompatible changes

##(*ClientEncryption).AddKeyAltName: changed from func(context.Context, ./bson/primitive.Binary, string) *SingleResult to func(context.Context, ./bson.Binary, string) SingleResult
##(ClientEncryption).CreateDataKey: changed from func(context.Context, string, ..../mongo/options.DataKeyOptions) (./bson/primitive.Binary, error) to func(context.Context, string, ...
./mongo/options.DataKeyOptions) (./bson.Binary, error)
##(*ClientEncryption).CreateEncryptedCollection: changed from func(context.Context, *Database, string, *./mongo/options.CreateCollectionOptions, string, interface{}) (*Collection, ./bson/primitive.M, error) to func(context.Context, *Database, string, *./mongo/options.CreateCollectionOptions, string, interface{}) (*Collection, ./bson.M, error)
##(*ClientEncryption).Decrypt: changed from func(context.Context, ./bson/primitive.Binary) (./bson.RawValue, error) to func(context.Context, ./bson.Binary) (./bson.RawValue, error)
##(*ClientEncryption).DeleteKey: changed from func(context.Context, ./bson/primitive.Binary) (*DeleteResult, error) to func(context.Context, ./bson.Binary) (DeleteResult, error)
##(ClientEncryption).Encrypt: changed from func(context.Context, ./bson.RawValue, ..../mongo/options.EncryptOptions) (./bson/primitive.Binary, error) to func(context.Context, ./bson.RawValue, ...
./mongo/options.EncryptOptions) (./bson.Binary, error)
##(*ClientEncryption).GetKey: changed from func(context.Context, ./bson/primitive.Binary) *SingleResult to func(context.Context, ./bson.Binary) *SingleResult
##(*ClientEncryption).RemoveKeyAltName: changed from func(context.Context, ./bson/primitive.Binary, string) *SingleResult to func(context.Context, ./bson.Binary, string) SingleResult
##(GridFSBucket).UploadFromStream: changed from func(context.Context, string, io.Reader, ..../mongo/options.UploadOptions) (./bson/primitive.ObjectID, error) to func(context.Context, string, io.Reader, ...
./mongo/options.UploadOptions) (./bson.ObjectID, error)
##CollectionSpecification.UUID: changed from *./bson/primitive.Binary to *./bson.Binary
##NewCursorFromDocuments: changed from func([]interface{}, error, *./bson/bsoncodec.Registry) (*Cursor, error) to func([]interface{}, error, *./bson.Registry) (*Cursor, error)
##NewSingleResultFromDocument: changed from func(interface{}, error, *./bson/bsoncodec.Registry) *SingleResult to func(interface{}, error, ./bson.Registry) SingleResult
##Pipeline: changed from []./bson/primitive.D to []./bson.D
##Session.AdvanceOperationTime: changed from func(
./bson/primitive.Timestamp) error to func(
./bson.Timestamp) error
##Session.OperationTime: changed from func() *./bson/primitive.Timestamp to func() *./bson.Timestamp

./mongo/description

incompatible changes

##SelectedServer.ElectionID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##SelectedServer.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##Server.ElectionID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID
##Server.ServiceID: changed from *./bson/primitive.ObjectID to *./bson.ObjectID
##TopologyVersion.ProcessID: changed from ./bson/primitive.ObjectID to ./bson.ObjectID

./mongo/options

incompatible changes

##(*AggregateOptions).SetCustom: changed from func(./bson/primitive.M) *AggregateOptions to func(./bson.M) *AggregateOptions
##(*ChangeStreamOptions).SetCustom: changed from func(./bson/primitive.M) *ChangeStreamOptions to func(./bson.M) *ChangeStreamOptions
##(*ChangeStreamOptions).SetCustomPipeline: changed from func(./bson/primitive.M) *ChangeStreamOptions to func(./bson.M) *ChangeStreamOptions
##(ChangeStreamOptions).SetStartAtOperationTime: changed from func(./bson/primitive.Timestamp) ChangeStreamOptions to func(./bson.Timestamp) *ChangeStreamOptions
##(ClientOptions).SetRegistry: changed from func(./bson/bsoncodec.Registry) ClientOptions to func(./bson.Registry) *ClientOptions
##(CollectionOptions).SetRegistry: changed from func(./bson/bsoncodec.Registry) CollectionOptions to func(./bson.Registry) *CollectionOptions
##(DatabaseOptions).SetRegistry: changed from func(./bson/bsoncodec.Registry) DatabaseOptions to func(./bson.Registry) *DatabaseOptions
##(*EncryptOptions).SetKeyID: changed from func(./bson/primitive.Binary) *EncryptOptions to func(./bson.Binary) *EncryptOptions
##AggregateOptions.Custom: changed from ./bson/primitive.M to ./bson.M
##ArrayFilters.Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry
##ChangeStreamOptions.Custom: changed from ./bson/primitive.M to ./bson.M
##ChangeStreamOptions.CustomPipeline: changed from ./bson/primitive.M to ./bson.M
##ChangeStreamOptions.StartAtOperationTime: changed from *./bson/primitive.Timestamp to *./bson.Timestamp
##ClientOptions.Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry
##CollectionOptions.Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry
##DatabaseOptions.Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry
##EncryptOptions.KeyID: changed from *./bson/primitive.Binary to *./bson.Binary
##UploadOptions.Registry: changed from *./bson/bsoncodec.Registry to *./bson.Registry

./mongo/readconcern

incompatible changes

##(*ReadConcern).MarshalBSONValue: changed from func() (./bson/bsontype.Type, []byte, error) to func() (./bson.Type, []byte, error)

./mongo/writeconcern

incompatible changes

##(*WriteConcern).MarshalBSONValue: changed from func() (./bson/bsontype.Type, []byte, error) to func() (./bson.Type, []byte, error)

./x/bsonx/bsoncore

incompatible changes

##(*ArrayBuilder).AppendDBPointer: changed from func(string, ./bson/primitive.ObjectID) *ArrayBuilder to func(string, [12]byte) *ArrayBuilder
##(*ArrayBuilder).AppendDecimal128: changed from func(./bson/primitive.Decimal128) *ArrayBuilder to func(uint64, uint64) *ArrayBuilder
##(*ArrayBuilder).AppendObjectID: changed from func(./bson/primitive.ObjectID) *ArrayBuilder to func([12]byte) *ArrayBuilder
##(*DocumentBuilder).AppendDBPointer: changed from func(string, string, ./bson/primitive.ObjectID) *DocumentBuilder to func(string, string, [12]byte) *DocumentBuilder
##(*DocumentBuilder).AppendDecimal128: changed from func(string, ./bson/primitive.Decimal128) *DocumentBuilder to func(string, uint64, uint64) *DocumentBuilder
##(*DocumentBuilder).AppendObjectID: changed from func(string, ./bson/primitive.ObjectID) *DocumentBuilder to func(string, [12]byte) *DocumentBuilder
##AppendDBPointer: changed from func([]byte, string, ./bson/primitive.ObjectID) []byte to func([]byte, string, [12]byte) []byte
##AppendDBPointerElement: changed from func([]byte, string, string, ./bson/primitive.ObjectID) []byte to func([]byte, string, string, [12]byte) []byte
##AppendDecimal128: changed from func([]byte, ./bson/primitive.Decimal128) []byte to func([]byte, uint64, uint64) []byte
##AppendDecimal128Element: changed from func([]byte, string, ./bson/primitive.Decimal128) []byte to func([]byte, string, uint64, uint64) []byte
##AppendHeader: changed from func([]byte, ./bson/bsontype.Type, string) []byte to func([]byte, Type, string) []byte
##AppendObjectID: changed from func([]byte, ./bson/primitive.ObjectID) []byte to func([]byte, [12]byte) []byte
##AppendObjectIDElement: changed from func([]byte, string, ./bson/primitive.ObjectID) []byte to func([]byte, string, [12]byte) []byte
##AppendType: changed from func([]byte, ./bson/bsontype.Type) []byte to func([]byte, Type) []byte
##ElementTypeError.Type: changed from ./bson/bsontype.Type to Type
##EqualValue: changed from func(./bson/bsontype.Type, ./bson/bsontype.Type, []byte, []byte) bool to func(Type, Type, []byte, []byte) bool
##InvalidDepthTraversalError.Type: changed from ./bson/bsontype.Type to Type
##ReadDBPointer: changed from func([]byte) (string, ./bson/primitive.ObjectID, []byte, bool) to func([]byte) (string, [12]byte, []byte, bool)
##ReadDecimal128: changed from func([]byte) (./bson/primitive.Decimal128, []byte, bool) to func([]byte) (uint64, uint64, []byte, bool)
##ReadHeader: changed from func([]byte) (./bson/bsontype.Type, string, []byte, bool) to func([]byte) (Type, string, []byte, bool)
##ReadObjectID: changed from func([]byte) (./bson/primitive.ObjectID, []byte, bool) to func([]byte) ([12]byte, []byte, bool)
##ReadType: changed from func([]byte) (./bson/bsontype.Type, []byte, bool) to func([]byte) (Type, []byte, bool)
##ReadValue: changed from func([]byte, ./bson/bsontype.Type) (Value, []byte, bool) to func([]byte, Type) (Value, []byte, bool)
##Value.DBPointer: changed from func() (string, ./bson/primitive.ObjectID) to func() (string, [12]byte)
##Value.DBPointerOK: changed from func() (string, ./bson/primitive.ObjectID, bool) to func() (string, [12]byte, bool)
##Value.Decimal128: changed from func() ./bson/primitive.Decimal128 to func() (uint64, uint64)
##Value.Decimal128OK: changed from func() (./bson/primitive.Decimal128, bool) to func() (uint64, uint64, bool)
##Value.ObjectID: changed from func() ./bson/primitive.ObjectID to func() [12]byte
##Value.ObjectIDOK: changed from func() (./bson/primitive.ObjectID, bool) to func() ([12]byte, bool)
##Value.Type: changed from ./bson/bsontype.Type to Type

compatible changes

Type: added
TypeArray: added
TypeBinary: added
TypeBoolean: added
TypeCodeWithScope: added
TypeDBPointer: added
TypeDateTime: added
TypeDecimal128: added
TypeDouble: added
TypeEmbeddedDocument: added
TypeInt32: added
TypeInt64: added
TypeJavaScript: added
TypeMaxKey: added
TypeMinKey: added
TypeNull: added
TypeObjectID: added
TypeRegex: added
TypeString: added
TypeSymbol: added
TypeTimestamp: added
TypeUndefined: added

./x/mongo/driver/mongocrypt/options

incompatible changes

##(*ExplicitEncryptionOptions).SetKeyID: changed from func(./bson/primitive.Binary) *ExplicitEncryptionOptions to func(./bson.Binary) *ExplicitEncryptionOptions
##ExplicitEncryptionOptions.KeyID: changed from *./bson/primitive.Binary to *./bson.Binary

./x/mongo/driver/session

incompatible changes

##(Client).AdvanceOperationTime: changed from func(./bson/primitive.Timestamp) error to func(*./bson.Timestamp) error
##Client.OperationTime: changed from *./bson/primitive.Timestamp to *./bson.Timestamp
##Client.SnapshotTime: changed from *./bson/primitive.Timestamp to *./bson.Timestamp

./x/mongo/driver/topology

incompatible changes

##(*Server).ProcessHandshakeError: changed from func(error, uint64, *./bson/primitive.ObjectID) to func(error, uint64, *./bson.ObjectID)
##ConnectServer: changed from func(./mongo/address.Address, updateTopologyCallback, ./bson/primitive.ObjectID, ...ServerOption) (*Server, error) to func(./mongo/address.Address, updateTopologyCallback, ./bson.ObjectID, ...ServerOption) (*Server, error)
##NewServer: changed from func(./mongo/address.Address, ./bson/primitive.ObjectID, ...ServerOption) *Server to func(./mongo/address.Address, ./bson.ObjectID, ...ServerOption) Server
##WithRegistry: changed from func(func(
./bson/bsoncodec.Registry) ./bson/bsoncodec.Registry) ServerOption to func(func(./bson.Registry) *./bson.Registry) ServerOption

@qingyang-hu qingyang-hu force-pushed the godriver2612 branch 8 times, most recently from c21ae43 to 8e381fb Compare February 21, 2024 16:23
Copy link
Collaborator Author

@qingyang-hu qingyang-hu Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to bson/bsonrw_test.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to bson/bson.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to bson/bson_test.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to bson/registry.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to bson/mode.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to bson/types.go

@blink1073 blink1073 changed the title GODRIVER-2612 GODRIVER-2612 Remove all references to the bson/primitive/bsonrw packages from bsoncore Feb 22, 2024
@qingyang-hu qingyang-hu force-pushed the godriver2612 branch 5 times, most recently from 1fe66e2 to 8d409a1 Compare February 26, 2024 15:55
@qingyang-hu qingyang-hu changed the title GODRIVER-2612 Remove all references to the bson/primitive/bsonrw packages from bsoncore GODRIVER-2612 Merge bsoncodec , bsontype, bsonrw, mgocompat, primitive into bson. Feb 26, 2024
@qingyang-hu qingyang-hu marked this pull request as ready for review February 26, 2024 19:17
@qingyang-hu qingyang-hu requested a review from a team as a code owner February 26, 2024 19:17
@qingyang-hu qingyang-hu requested review from blink1073, matthewdale and prestonvasquez and removed request for a team and blink1073 February 26, 2024 19:17
@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the review-priority-low Low Priority PR for Review: within 3 business days label Feb 27, 2024
@qingyang-hu qingyang-hu added review-priority-normal Medium Priority PR for Review: within 1 business day and removed review-priority-low Low Priority PR for Review: within 3 business days labels Feb 27, 2024
Comment on lines 34 to 36
type Setter interface {
SetBSON(raw bson.RawValue) error
SetBSON(raw RawValue) error
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned merging the mgocompat package into the bson package may create some namespacing problems. I know that was part of the original scope, but looking at the results, it's not clear that it makes sense. Since mgocompat only configures alternative encode/decode behaviors via a Registry and is not used by any of the core BSON logic, there's little risk of import cycles. Should we keep mgocompat a separate package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how long we will support the compatibility with mgo?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as mgo BSON marshal/unmarshal compatibility, I think we need to support it indefinitely. Customers with data in a database that was marshaled with mgo may continue to need unmarshaling compatibility unless they rewrite all incompatible documents with the Go Driver.

@qingyang-hu qingyang-hu requested a review from matthewdale March 7, 2024 23:02
@blink1073 blink1073 changed the title GODRIVER-2612 Merge bsoncodec, bsontype, bsonrw, mgocompat, primitive into bson. GODRIVER-2612 Merge bsoncodec, bsontype, bsonrw, primitive into bson. Mar 8, 2024
@blink1073
Copy link
Member

@qingyang-hu there is a conflict in bson/marshal.go

err = src.ReadMaxKey()
if err != nil {
break
}
err = dst.WriteMaxKey()
default:
err = fmt.Errorf("Cannot copy unknown BSON type %s", src.Type())
err = fmt.Errorf("cannot copy unknown BSON type %s", src.Type())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = fmt.Errorf("cannot copy unknown BSON type %s", src.Type())
err = fmt.Errorf("cannot copy unknown BSON type %q", src.Type())

return primitive.NilObjectID, fmt.Errorf("$oid value should be string, but instead is %s", ejv.t)
func (ejv *extJSONValue) parseObjectID() (ObjectID, error) {
if ejv.t != TypeString {
return NilObjectID, fmt.Errorf("$oid value should be string, but instead is %s", ejv.t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return NilObjectID, fmt.Errorf("$oid value should be string, but instead is %s", ejv.t)
return NilObjectID, fmt.Errorf("$oid value should be string, but instead is %q", ejv.t)

@@ -128,14 +126,14 @@ func (rv RawValue) String() string { return convertToCoreValue(rv).String() }
func (rv RawValue) DebugString() string { return convertToCoreValue(rv).DebugString() }

// Double returns the float64 value for this element.
// It panics if e's BSON type is not bsontype.Double.
// It panics if e's BSON type is not bson.TypeDouble.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we specify "bson.*" in comments in the bson package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the convention of the bson package.

oid, ok := v.ObjectIDOK()
if !ok {
return ""
}
return fmt.Sprintf(`{"$oid":"%s"}`, oid.Hex())
case bsontype.Boolean:
return fmt.Sprintf(`{"$oid":"%s"}`, idHex(oid))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the original method work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The v.ObjectIDOK() at L254 returns [12]byte in this PR to avoid the import cycle. See the change at L523.

if subtype != bsontype.BinaryGeneric && subtype != bsontype.BinaryBinaryOld {
return fmt.Errorf("SliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %s, got %v", bsontype.Binary, subtype)
if subtype != TypeBinaryGeneric && subtype != TypeBinaryBinaryOld {
return fmt.Errorf("SliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %s, got %v", TypeBinary, subtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("SliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %s, got %v", TypeBinary, subtype)
return fmt.Errorf("SliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %q, got %q", TypeBinary, subtype)

prestonvasquez
prestonvasquez previously approved these changes Apr 5, 2024
Copy link
Member

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package seems dedicated to decimal128 functionality, so makes more sense to move to internal/decimal128.

}

// AppendObjectID will append oid to dst and return the extended buffer.
func AppendObjectID(dst []byte, oid primitive.ObjectID) []byte { return append(dst, oid[:]...) }
func AppendObjectID(dst []byte, oid [idLen]byte) []byte { return append(dst, oid[:]...) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining idLen = 12 and then using type [idLen]byte everywhere, you can use a type alias to prevent having to type [12]byte everywhere.

E.g.

type objectID = [12]byte

func AppendObjectID(dst []byte, oid objectID) []byte { return append(dst, oid[:]...) }

To callers outside of the bsoncore package, the function signature will just look like

func AppendObjectID(dst []byte, oid [12]byte) []byte

but you won't have to type [12]byte everywhere.

Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@qingyang-hu qingyang-hu merged commit a06ace2 into mongodb:master Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-priority-normal Medium Priority PR for Review: within 1 business day
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants