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: decode map not eqaul encode value #20449

niubaoshu opened this issue May 22, 2017 · 4 comments

encoding/gob: decode map not eqaul encode value #20449

niubaoshu opened this issue May 22, 2017 · 4 comments


Copy link

@niubaoshu niubaoshu commented May 22, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 windows/amd64

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\work\go
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build270790435=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on is best.

What did you expect to see?


What did you see instead?

this is a bug?

Copy link

@odeke-em odeke-em commented May 22, 2017

Hello there @niubaoshu, is the bug you are reporting that mm map[int]string{"2": 2} when passed into dec.Decode(&mm) should have been entirely reset thus making it map[int]string{"1": 1} after decoding?

If so, my personal opinion is that that would be unexpected unless you have conflicting keys(in which that's implicit with a map for clashing keys); decoding values into a receiver is setting them in the receiver, and I don't see any promises of the proposed behavior in the encoding/gob docs
screen shot 2017-05-22 at 12 41 07 am

Let me ping some of the owners of the package @robpike @bradfitz, to give some input.

Copy link

@niubaoshu niubaoshu commented May 22, 2017

Copy link

@odeke-em odeke-em commented May 22, 2017

Hmm, interesting. For comparison with other encoding/ packages, I've made

I'll defer to the decisions of the folks that I pinged earlier as I don't fully understand the correct behavior. Thank you for reporting the bug!

Copy link

@robpike robpike commented May 22, 2017

Working as intended. The decoder does not zero out the object before storing the values.

@robpike robpike closed this May 22, 2017
@golang golang locked and limited conversation to collaborators May 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.