encoding/gob: doc of encoding of single values is inconsistent

55 views
Skip to first unread message

Jared Zhou

unread,
Dec 8, 2021, 11:15:27 PM12/8/21
to golang-nuts
The doc says. 
If a value is passed to Encode and the type is not a struct (or pointer to struct, etc.), for simplicity of processing it is represented as a struct of one field. The only visible effect of this is to encode a zero byte after the value, just as after the last field of an encoded struct.

But here says, https://github.com/golang/go/blob/d6c4583ad4923533ddc9f5792ed3b66f3b9f9feb/src/encoding/gob/doc.go#L402

A single non-struct value at top level is transmitted like a field with


delta tag 0
. For instance, a signed integer with value 3 presented as


the argument to Encode will emit:




03 04 00 06




Which represents:




03 // this value is 3 bytes long


04 // the type number, 2, represents an integer


00 // tag delta 0


06 // value 3

It seems the later one is correct? Related issue encoding/gob: encoding of single values doesn't agree with documentation

Reply all
Reply to author
Forward
0 new messages