aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/gob
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2017-03-20 20:24:26 -0700
committerRob Pike <r@golang.org>2017-03-21 04:07:46 +0000
commit67a46cc1636362bea54ab68b521f77a778968ea2 (patch)
tree5cdf9496c3f231ee325e9fc6ee88ec3a236a8d66 /src/encoding/gob
parent5c5a10690e56bf127832b98d73c83720e0093eef (diff)
downloadgo-67a46cc1636362bea54ab68b521f77a778968ea2.tar.gz
go-67a46cc1636362bea54ab68b521f77a778968ea2.zip
encoding/gob: document the extra byte after a singleton
This paragraph has been added, as the notion was missing from the documentation. 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, so that the decode algorithm knows when the top-level value is complete. Fixes #16978 Change-Id: I5f008e792d1b6fe80d2e026a7ff716608889db32 Reviewed-on: https://go-review.googlesource.com/38414 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/gob')
-rw-r--r--src/encoding/gob/doc.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/encoding/gob/doc.go b/src/encoding/gob/doc.go
index 1536574fed..554d1134ad 100644
--- a/src/encoding/gob/doc.go
+++ b/src/encoding/gob/doc.go
@@ -175,6 +175,12 @@ the interface value. (A nil interface value is identified by the empty string
and transmits no value.) Upon receipt, the decoder verifies that the unpacked
concrete item satisfies the interface of the receiving variable.
+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, so that the decode algorithm knows when
+the top-level value is complete.
+
The representation of types is described below. When a type is defined on a given
connection between an Encoder and Decoder, it is assigned a signed integer type
id. When Encoder.Encode(v) is called, it makes sure there is an id assigned for