For a single object, not a struct, it still gets sent as a struct with one field. The 0 is the marker after the last (only) field is sent.
-rob On Mon, Feb 27, 2017 at 10:53 PM, Sam Whited <[email protected]> wrote: > Hi all, > > I'm writing an implementation of the Gob serialization format in > another language, but am seeing some extra bytes that, as far as I can > tell, aren't described in the documentation. For example, if I encode > a simple bool (https://play.golang.org/p/shFJnM3WgM) I get: > > > 03 02 00 01 > > I understand this to mean 03 (remaining bytes) 02 (signed int type ID > for boolean) 00 (???) 01 (uint 1 == true). I don't understand where > the 00 comes from. > > Stepping through the code reveals that it's written by the update method: > > > // update emits a field number and updates the state to record its value > for delta encoding. > > // If the instruction pointer is nil, it does nothing > > func (state *encoderState) update(instr *encInstr) > > But this is not a struct, it's a bool, so I'm a bit confused as to why > update would be called in the first place. I'd just assume a 0 field > value is written for everything that's not a struct, but this doesn't > appear to align with the grammar as specified in the docs: > > > (byteCount (-type id, encoding of a wireType)* (type id, encoding of a > value))* > > I've read through the docs four or five times now, and still don't see > where the field number is documented (except for structs); is this a > faiure of the documentation, or am I just missing the obvious? > > Thanks, > Sam > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
