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: does not overwrite zero values of structures #22862

Closed
afunix opened this issue Nov 24, 2017 · 2 comments
Closed

encoding/gob: does not overwrite zero values of structures #22862

afunix opened this issue Nov 24, 2017 · 2 comments
Assignees
Milestone

Comments

@afunix
Copy link

@afunix afunix commented Nov 24, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cqx874/projects/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/84/h3xfrt592ss8j1199p0sg4bc0000gn/T/go-build983167319=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I have a stream generated by GobEncoder which is being read in a cycle by GobDecoder.

Documentation states:

        // GobDecode overwrites the receiver, which must be a pointer,
        // with the value represented by the byte slice, which was written
        // by GobEncode, usually for the same concrete type.

However if any field in the structure being received is zero, it won't be populated by GobDecorer.Decode().

Example: https://play.golang.org/p/ifu1Bj2j_v

What did you expect to see?

decoded: {10}
decoded: {0}
decoded: {20}

What did you see instead?

decoded: {10}
decoded: {10}
decoded: {20}

@bradfitz bradfitz changed the title encoding/gob does not overwrite zero values of structures encoding/gob: does not overwrite zero values of structures Nov 24, 2017
@bradfitz bradfitz added this to the Go1.11 milestone Nov 24, 2017
@robpike
Copy link
Contributor

@robpike robpike commented Nov 24, 2017

Working as intended. Duplicate of #21929

@robpike robpike closed this Nov 24, 2017
@afunix
Copy link
Author

@afunix afunix commented Nov 24, 2017

Can you please at least update documentation, so this design is more obvious?
I spent 3 hours reading through encoding/gob code and binary data it generates to find out this behaviour.

@golang golang locked and limited conversation to collaborators Nov 24, 2018
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
4 participants
You can’t perform that action at this time.