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

Comments

@robzan8
Copy link

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 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 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

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

@robzan8
Copy link
Author

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 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

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

@robpike robpike closed this as completed in 148b13c Dec 7, 2015
@golang golang locked and limited conversation to collaborators Dec 14, 2016
@rsc rsc unassigned robpike Jun 23, 2022
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

3 participants