Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/binary: Handle struct padding in binary.Read #4185

Closed
mxk opened this issue Oct 2, 2012 · 4 comments
Closed

encoding/binary: Handle struct padding in binary.Read #4185

mxk opened this issue Oct 2, 2012 · 4 comments
Milestone

Comments

@mxk
Copy link

mxk commented Oct 2, 2012

When encoding/decoding structs, it is often useful to insert padding between fields,
especially when working with foreign data formats. Using anonymous field names
(underscore) is the most natural way to do this. binary.Write handles this just fine,
but binary.Read panics because the field '_' is unexported. If possible, this should be
handled as a special case.

What steps will reproduce the problem?
http://play.golang.org/p/uDI-I9saFy

What is the expected output?
01 00 00 00 00 00 00 00 02 00 00 00
{1 [0 0 0 0] 2}

What do you see instead?
01 00 00 00 00 00 00 00 02 00 00 00
panic: reflect.Value.SetUint using value obtained using unexported field
...

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Windows 7

Which version are you using?  (run 'go version')
1.0.3
@griesemer
Copy link
Contributor

Comment 1:

This request seems not unreasonable. Since _ fields cannot be accessed anyway within the
language, it would be fine to skip the respective data when decoding into a struct with
_ fields.

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 2:

Owner changed to @griesemer.

@rsc
Copy link
Contributor

rsc commented Oct 6, 2012

Comment 3:

Labels changed: added go1.1.

@griesemer
Copy link
Contributor

Comment 4:

This issue was closed by revision 27c990e.

Status changed to Fixed.

@mxk mxk added fixed labels Nov 1, 2012
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants