]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: clarify docs about pointers to zero values not being sent
authorOleg Zaytsev <mail@olegzaytsev.com>
Fri, 26 Dec 2025 20:11:01 +0000 (20:11 +0000)
committerCherry Mui <cherryyz@google.com>
Mon, 29 Dec 2025 20:45:08 +0000 (12:45 -0800)
The documentation on encoding/gob mentions that pointers are flattened,
and it also explicitly says that empty values are not sent.

A corollary of this, is that pointers to zero values are not sent, i.e.,
gob-encoding of *false becomes nil on the receiver side.

It is worth documenting this explicitly.

Change-Id: I1909203b8972e20791144bdda22e5f1b466aad97
GitHub-Last-Rev: 57764ec235ffe48484be98d3ed5269f0102ca4f8
GitHub-Pull-Request: golang/go#77009
Reviewed-on: https://go-review.googlesource.com/c/go/+/732820
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/encoding/gob/doc.go

index c746806887ab3d40cce943ace3ede17cd708cae7..390f25088e3dab8a6888bad831874354582a0708 100644 (file)
@@ -153,16 +153,16 @@ are transmitted, even if all the elements are zero.
 
 Structs are sent as a sequence of (field number, field value) pairs. The field
 value is sent using the standard gob encoding for its type, recursively. If a
-field has the zero value for its type (except for arrays; see above), it is omitted
-from the transmission. The field number is defined by the type of the encoded
-struct: the first field of the encoded type is field 0, the second is field 1,
-etc. When encoding a value, the field numbers are delta encoded for efficiency
-and the fields are always sent in order of increasing field number; the deltas are
-therefore unsigned. The initialization for the delta encoding sets the field
-number to -1, so an unsigned integer field 0 with value 7 is transmitted as unsigned
-delta = 1, unsigned value = 7 or (01 07). Finally, after all the fields have been
-sent a terminating mark denotes the end of the struct. That mark is a delta=0
-value, which has representation (00).
+field has the zero value for its type (except for arrays; see above) or it's a
+pointer to a zero value, it is omitted from the transmission. The field number
+is defined by the type of the encoded struct: the first field of the encoded type
+is field 0, the second is field 1, etc. When encoding a value, the field numbers
+are delta encoded for efficiency and the fields are always sent in order of
+increasing field number; the deltas are therefore unsigned. The initialization
+for the delta encoding sets the field number to -1, so an unsigned integer field 0
+with value 7 is transmitted as unsigned delta = 1, unsigned value = 7 or (01 07).
+Finally, after all the fields have been sent a terminating mark denotes the end
+of the struct. That mark is a delta=0 value, which has representation (00).
 
 Interface types are not checked for compatibility; all interface types are
 treated, for transmission, as members of a single "interface" type, analogous to