You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I read through some similar issues, it seems that when decoding, the object buffer will not be cleared out. So I guess this may be a expected outcome as in language spec. Then I think in example code, it should be strongly discouraged to reuse the object buffer.
But, as I was reading examples (https://golang.org/src/encoding/gob/example_test.go). The example clearly reuse the object q to read decoded value twice. As a C/C++ programmer, there is strong inclination to reuse a buffer if possible.
This behavior is much more deadly as I was transmitting a boolean, a false never reaches if the previous value is true. This means this library is very easy to use wrongly.
The text was updated successfully, but these errors were encountered:
IINM, this is working as intended and cannot be changed. It's how zero-values handling was designed to work and it saves wire-data when there's a lot of them. I think the designer(s) had experienced zero-values being common enough to justify this.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Just playing with playground.
Does this issue reproduce with the latest release?
N/A
What operating system and processor architecture are you using (
go env
)?N/A
What did you do?
https://play.golang.org/p/_nm1UhGT67
What did you expect to see?
1
0
-1
What did you see instead?
1
1
-1
As I read through some similar issues, it seems that when decoding, the object buffer will not be cleared out. So I guess this may be a expected outcome as in language spec. Then I think in example code, it should be strongly discouraged to reuse the object buffer.
But, as I was reading examples (https://golang.org/src/encoding/gob/example_test.go). The example clearly reuse the object q to read decoded value twice. As a C/C++ programmer, there is strong inclination to reuse a buffer if possible.
This behavior is much more deadly as I was transmitting a boolean, a false never reaches if the previous value is true. This means this library is very easy to use wrongly.
The text was updated successfully, but these errors were encountered: