Closed heri16 closed 2 years ago
Instead of trying to encode "unexported" fields, I would add checking for the method Marshal() in the encoder and Unmarshal() for the TermIntoStruct/TermMapIntoStruct accordingly. I believe, "unexported" field must be hidden from the outside world. That's why they called it "unexported" isn't it? :)
var bin []byte
var err error
if obj, ok := term.(interface{Marshal()}); ok {
bin, err = obj.Marshal()
...
}
There is Marshal/Unmarshal feature in the coming release. So this PR won't be accepted.
not valid any more
Nice one
Instead of trying to encode "unexported" fields, I would add checking for the method Marshal() in the encoder and Unmarshal() for the TermIntoStruct/TermMapIntoStruct accordingly. I believe, "unexported" field must be hidden from the outside world. That's why they called it "unexported" isn't it? :)
var bin []byte var err error if obj, ok := term.(interface{Marshal()}); ok { bin, err = obj.Marshal() ... }
That may be true most of the time, but not all the time. Third-party libraries commonly have structs that have unexported fields that cannot be accessed unless you can modify the third-party source code to add accessor methods.
And unmarshall / marshall methods that you add would not be able to read those same unexported fields.
If the goal is transparent and efficient transport of in-memory state across the wire, then the use case could be valid.
Documenting how this could be done via the new ergo API would be great.
Fixes #63
Changes:
encoding.TextMarshaler
on unaddressable goStructs (e.g. golang stdlib time.Now())Depends on #68