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

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

    XMLWordPrintable

    Details

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

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            divjot.arora Divjot Arora
            Reporter:
            divjot.arora Divjot Arora
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: