[GODRIVER-645] lookupInterfaceDecoder does not ensure type is a pointer Created: 21/Nov/18  Updated: 28/Oct/23  Resolved: 04/Dec/18

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

Type: Bug Priority: Major - P3
Reporter: Eric Daniels (Inactive) Assignee: Kristofer Brandow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

A type that has a property of another struct that proxies a primitive like a string cannot be unmarshaled after being marshaled with the following error: "positioned on string, but attempted to read embedded document".

Example code:

type encValueWrapper struct {
    EncValue EncryptedValue
}
 
type EncryptedValue struct {
    value    string
    rawValue []byte
}
 
func (ev EncryptedValue) DecryptValue(crypter Crypter, out interface{}) error {
    if ev.value != "" {
        return crypter.DecryptValue(ev.value, out)
    }
    return crypter.DecryptParsedValue(ev.rawValue, out)
}
 
func (ev EncryptedValue) ProxyBSON() (interface{}, error) {
    if ev.value == "" {
        return nil, ErrNotEncryptedValue
    }
    return ev.value, nil
}
 
func (ev *EncryptedValue) UnmarshalBSONValue(t bsontype.Type, data []byte) error {
    temp, err := NewEncryptedValueFromBSON(bson.RawValue{Type: t, Value: data})
    if err != nil {
        return err
    }
    *ev = temp
    return nil
}



 Comments   
Comment by Githook User [ 04/Dec/18 ]

Author:

{'name': 'Kris Brandow', 'email': 'kris@mongodb.com', 'username': 'skriptble'}

Message: Update codec system to use reflect.Value

Add support for pointers to the BSON codec system. When doing an
interface lookup for a decoder, we now check if the type or a pointer to
the type implement the interface. If either one does, we return the
decoder for that interface.

This change changes the ValueEncoder and ValueDecoder interfaces to use
reflect.Value instead of interface{}.

Move the bson.D family of types into the primitive package.

GODRIVER-535
GODRIVER-598
GODRIVER-588
GODRIVER-645
GODRIVER-662
GODRIVER-649
GODRIVER-670

Change-Id: Idec68f74e354973160bd59f9f8fef009f026f943
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/d305fc0b97b199028c9a7def35f931224c448665

Comment by Kristofer Brandow (Inactive) [ 28/Nov/18 ]

Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/435374.

Comment by Ian Whalen (Inactive) [ 26/Nov/18 ]

Marking as 0.1.0 so we don't lose this, but hoping this will just be fixed user-side.

Comment by Ian Whalen (Inactive) [ 26/Nov/18 ]

eric.daniels can you change the EncValue property to a pointer?

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