encoding/gob: encoding of single values doesn't agree with documentation #16978
Labels
Documentation
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mero"
GORACE=""
GOROOT="/home/mero/go"
GOTOOLDIR="/home/mero/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build316359239=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
What did you do?
https://play.golang.org/p/tXSmbPjlD2
What did you expect to see?
Above program printing
[]byte{0x2,0x6,0x1}
(see comment for why)What did you see instead?
Above program printing
[]byet{0x3, 0x6, 0x0, 0x1}
with an extra 0-byte.I tried very hard to find any mention of what this 0-byte means in the documentation but couldn't find anything (though I can't conclusively say it isn't there :) ). This only happens for single primitive values (not for structs) and I think it's an artifact of how the state machine works (i.e. it emits an end-of-struct-tag, even though there never was one).
As the 0-byte carries no information, this is probably a bug in the encoder, but as there probably is encoding of this in the wild and gob isn't version, it probably can't be fixed. In that case, the documentation should be updated to include this.
The text was updated successfully, but these errors were encountered: