Make "bson.Type" a type alias instead of a distinct type

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • 3.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • Go Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      In Go Driver v2, we changed the signature of the bson.ValueMarshaler interface (i.e. the MarshalBSONValue function) to return byte instead of bsontype.Type. The intent was to allow 3rd-party libraries to implement the bson.ValueMarshaler interface without depending on the Go Driver module. However, that change created an inconsistency between the bson.MarshalValue function (returns bson.Type) and the bson.ValueMarshaler interface (returns byte). A better change would be to make bson.Type an alias of byte, which would keep the types identical but also not require depending on the Go Driver module to implement the interface.

      E.g.

      package bson
      
      type Type = byte
      
      type ValueMarshaler interface {
      	MarshalBSONValue() (typ byte, data []byte, err error)
      }
      
      func MarshalValue(val any) (Type, []byte, error)
      

      Note that we could change the MarshalBSONValue signature to return Type, but it's not clear if that would be confusing to users implementing the interface (i.e. they may think they need to return bson.Type and not realize they can return byte).

      Definition of done

      What must be done to consider the task complete?

      Pitfalls

      What should the implementer watch out for? What are the risks?

              Assignee:
              Unassigned
              Reporter:
              Matt Dale
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: