Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1438

Separate RegisterEncoder/Decoder functions to "types" and "hooks"

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      If an encoder is registered for an interface type, we'll call that encoder for all types that implement that interface as well. This was done so we could register encoders for types like bson.Marshaler and they would be called for all structs that implement bson.Marshaler. Users may want more fine-grained behavior, however. If an encoder is registered for io.Reader, a user may only want it to be called when marshalling an io.Reader and use the regular struct codec when marshalling a concrete type that implements io.Reader. The proposed way to do this is the following:

      1. Deprecate RegisterEncoder
      2. Add a new function to register a type encoder. In the case of interface types, the encoder will only be called when marshalling the interface type, not a concrete type that implements it.
      3. Add a new function to register a "hook" encoder. This will only accept interface types and the encoder will be called for any types that implement the interface. We'll use this for interfaces like bson.Marshaler 

      Everything listed above applies to decoders as well.

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: