[GODRIVER-1438] Separate RegisterEncoder/Decoder functions to "types" and "hooks" Created: 12/Dec/19  Updated: 28/Oct/23  Resolved: 08/Jan/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 1.3.0

Type: Improvement Priority: Major - P3
Reporter: Divjot Arora (Inactive) Assignee: Divjot Arora (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File main.go    

 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.



 Comments   
Comment by Githook User [ 08/Jan/20 ]

Author:

{'name': 'Divjot Arora', 'email': 'divjot.arora@10gen.com', 'username': 'divjotarora'}

Message: GODRIVER-1438 Add separate RegistryBuilder methods for types and hooks (#269)

Generated at Thu Feb 08 08:36:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.