What does 'go version' print?
go version go1.2 linux/amd64
What steps reproduce the problem?
Use binary.Write to marshal a struct with an unexported field, then attempt to unmarshal the resulting bytes using binary.Read
The reflect module panics when attempting to set the unexported field value, e.g:
"panic: reflect: reflect.Value.SetInt using value obtained using unexported field"
What should have happened instead?
The documentation clearly states unnamed fields are written out zeroed, but no verbiage exists for unexported fields.
Some potential ways forward:
* unexported fields could be written zeroed and skipped during reading (treat as unnamed fields).
* unexported fields could be skipped during reading and writing.
* continue to panic, but add explicit documentation about unexported field handling.
Blank field handling added in https://golang.org/cl/6750053
The text was updated successfully, but these errors were encountered:
i think ideally Write should just skip unexported fields, however, that is an API change.
so at this stage, we actually have only two options:
1. skip unexported fields during read (and document that),
2. panic as usual, document it.
I think option 1 is the way to go.
What do you think?
rsc objected to not-panicking in during Read in message #3 on the linked change, and we
don't want to change the output of Write, so I think this may be best addressed as a doc
That being said, I agree that Write should be skipping (or zeroing) unexported fields.
Requiring developers to implement BinaryMarshaler and BinaryUnmarshaler to get symmetric
behavior is unfortunate.