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

Deprecate all "*Append", "*WithRegistry", and "*WithContext" functions in the "bson" package

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.12.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The *Append, *WithRegistry, and *WithContext functions in the bson package are redundant and can be replaced by creating and configuring an Encoder or Decoder.

      Replacement Examples

      Marshal

      The MarshalAppend function can be replaced with:

      dst := new(bytes.Buffer)
      bson.NewEncoder(dst).Encode(val)
      

      The MarshalExtJSONAppend function can be replaced with:

      dst := new(bytes.Buffer)
      bson.NewExtJSONEncoder(dst).Encode(val)
      

      The Marshal*WithRegistry functions can be replaced with:

      dst := new(bytes.Buffer)
      enc := bson.NewEncoder(dst)
      enc.SetRegistry(reg)
      enc.Encode(val)
      

      The MarshalExtJSON*WithRegistry functions can be replaced with:

      dst := new(bytes.Buffer)
      enc := bson.NewExtJSONEncoder(dst)
      enc.SetRegistry(reg)
      enc.Encode(val)
      

      The Marshal*WithContext functions can be replaced with:

      dst := new(bytes.Buffer)
      enc := bson.NewEncoder(dst)
      enc.SetRegistry(reg)
      enc.SetMinSize(true)
      enc.Encode(val)
      

      Unmarshal

      The UnmarshalAppend function can be replaced with:

      dec := bson.NewDecoder(bytes.NewReader(data))
      dec.Decode(val)
      

      The UnmarshalExtJSONAppend function can be replaced with:

      dec := bson.NewExtJSONDecoder(bytes.NewReader(data))
      dec.Decode(val)
      

      The Unmarshal*WithRegistry functions can be replaced with:

      dec := bson.NewDecoder(bytes.NewReader(data))
      dec.SetRegistry(reg)
      dec.Decode(val)
      

      The UnmarshalExtJSON*WithRegistry functions can be replaced with:

      dec := bson.NewExtJSONDecoder(bytes.NewReader(data))
      dec.SetRegistry(reg)
      dec.Decode(val)
      

      The Unmarshal*WithContext functions can be replaced with:

      dec := bson.NewDecoder(bytes.NewReader(data))
      dec.SetRegistry(reg)
      dec.SetTruncate(true)
      dec.DefaultDocumentM()
      dec.Decode(val)
      

      Encoder/Decoder

      The NewEncoderWithContext function can be replaced with:

      dst := new(bytes.Buffer)
      enc := NewEncoder(dst)
      enc.SetRegistry(reg)
      enc.SetMinSize(true)
      

      The NewDecoderWithContext function can be replaced with:

      dec := bson.NewDecoder(bytes.NewReader(data))
      dec.SetRegistry(reg)
      dec.SetTruncate(true)
      dec.DefaultDocumentM()
      

      Definition of done

      • Deprecate all package functions and RawValue methods ending with *Append, *WithRegistry, or *WithContext.
      • Add example tests that describe how to replace the functionality offered by all deprecated functions.

            Assignee:
            matt.dale@mongodb.com Matt Dale
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: