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/gob: zero value array within a struct is transmitted #13378

Closed
robzan8 opened this issue Nov 24, 2015 · 6 comments
Closed

encoding/gob: zero value array within a struct is transmitted #13378

robzan8 opened this issue Nov 24, 2015 · 6 comments
Assignees

Comments

@robzan8
Copy link

@robzan8 robzan8 commented Nov 24, 2015

Documentation about struct encoding says: "If a field has the zero value for its type, it is omitted from the transmission."
It's actually not true for fields of array type:
https://play.golang.org/p/Zy8PIbmAGy

Is this working as intended?
I'm sorry to bother you here, but no one could answer me on go-nuts.

@robpike
Copy link
Contributor

@robpike robpike commented Nov 24, 2015

Yes, working as intended but not documented.

@robpike robpike self-assigned this Nov 24, 2015
@robpike robpike changed the title encoding/gob: zero value fields of array type are transmitted encoding/gob: document that zero value fields of arrays are transmitted Nov 24, 2015
@robzan8
Copy link
Author

@robzan8 robzan8 commented Nov 24, 2015

May I ask what is the reason for this behavior? A consequence I found surprising is that, If struct X contains even one small array, the whole struct will never figure as zero (and omitted) when X itself is a field of another struct Y.
https://play.golang.org/p/fQ4iqTsrHx

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 24, 2015

CL https://golang.org/cl/17201 mentions this issue.

@robpike robpike closed this in b790ad5 Nov 24, 2015
@robzan8
Copy link
Author

@robzan8 robzan8 commented Nov 24, 2015

Sorry guys, I could not comment on the CL in time. I believe that the documentation added does not address the issue.
It is very clear that zero elements inside arrays are transmitted. The issue is about struct fields. The doc says that zero value fields are omitted, and this implies that zero value fields of type array are omitted. In fact, a field of type slice with nil value is omitted. But a field of type array with zero value is not omitted. The existing documentation about struct fields is technically wrong. Hope I was clear enough. @ianlancetaylor

@robpike
Copy link
Contributor

@robpike robpike commented Nov 25, 2015

Reopening for further investigation and renaming.

@robpike robpike reopened this Nov 25, 2015
@robpike robpike changed the title encoding/gob: document that zero value fields of arrays are transmitted encoding/gob: zero value array within a struct is transmitted Nov 25, 2015
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 3, 2015

CL https://golang.org/cl/17394 mentions this issue.

@robpike robpike closed this in 148b13c Dec 7, 2015
@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.