Repository navigation
allow ptr in inline structs - #146
Conversation
|
Thanks for the PR - we'll take a proper look but seems like a great change! Dom |
| value = v.Field(info.Num) | ||
| } else { | ||
| value = v.FieldByIndex(info.Inline) | ||
| field, errField := safeFieldByIndex(v, info.Inline) |
There was a problem hiding this comment.
this change will silently skip encoding errors, where they used to panic before.
Not very familiar with the bson encoder anymore, @domodwyer thoughts?
There was a problem hiding this comment.
Encoder has a structInfo object, based only on type, not on value.
As we allow pointers to structs here, we can have chain of inline indices (info.Inline) and e.g. element behind a n-1 index might be nil, so trying to get element by index n will panic because of reflect: indirection through nil pointer to embedded struct
There was a problem hiding this comment.
I think this is probably fine either way - relying on the encoder to panic because the input was invalid is a bit of a stretch in terms of backwards-compatibility.
|
Would you pull the latest development into this branch and we'll get it merged! Thanks for taking the time to open a PR - it's really appreciated. Dom |
|
Branch is updated. Also a commit with some extra comments is added |
|
Thanks for taking the time to contribute 👍 Dom |
|
This only works when transforming data to bson to be written into mongo. When reading (populating the struct with) a record I still get the "reflect: indirection through nil pointer to embedded struct" error. |
|
@bojangavrovski hm. Ok, I'm looking into it |
BSON encoder doesn't allow to use pointers to struct in
inlinemode.There was an issue on the same topic on old repo:
https://github.com/go-mgo/mgo/issues/346
Such structure:
is assumed to become
{"a":0, "m":0}(withoutmstructstructure) - the same way asjsonencoder does itwithout fix we get: "reflect: indirection through nil pointer to embedded struct"