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: documentation incomplete(or wrongly implemented) #29057
Comments
/cc @robpike for further comments. |
Please show a complete, compact program that illustrates the problem. |
https://play.golang.org/p/idvKWcdTPiI By commenting out line 36(BWithPointerData()) you can see that it works when a pointer is given and not vice versa. |
This is how Go works. I'm not sure it's the gob's package job to explain the difference between the method sets of pointers and values. |
I think it would be more convenient if there would be a reference to the faq in the gob(and JSON...) documentation. |
If that "something" is not related to that type, I think that expectation is incorrect. If I am working with encoding/json, and I cannot figure out how slice append work, I do not expect that to be explained in the interface definition. Method sets are a design of the programming language itself and not specific to any package. I don't think adding a link to the FAQ just in gob and json, for something that is general to the programming language, is very helpful. It is clearly documented in the spec and also in the FAQ. I am going to close this as the original issue title is resolved. There is no issue with encoding/gob. If you feel method sets need to be documented more prominently, please feel free to open an issue with suggestions, and with reasoning explaining why the current documentation is not enough. Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I implemented the gob.GobEncoder (and gob.GobDecoder) interface(s) using pointer receivers on both ends.
What did you expect to see?
I expected to see gob calling my encoder and decoder to transmit the data
What did you see instead?
Gob doesn't use my encoder/decoder.
After debugging I could see that it does recognize that it implements both GobEncoder and GobDecoder, but for some reason doesn't use them.
After removing the * from the Encoder(making it a non-pointer receiver) receiver gob does use my implementation(successfully).
UPDATE:
I know that this is because I pass a non-pointer to enc.Encode() but this is was a bit frustrating.
Maybe just add a note that using a pointer receiver only works with pointer values, while non-pointer receivers work with both pointer and non-pointer receivers.
The text was updated successfully, but these errors were encountered: