1
0
mirror of https://github.com/golang/go synced 2024-11-19 08:34:39 -07:00

gob: package doc fixes.

R=r, r2, nigeltao_gnome
CC=golang-dev
https://golang.org/cl/2748041
This commit is contained in:
Nigel Tao 2010-10-27 10:46:00 +11:00
parent 0f28983afa
commit 3bb036958c

View File

@ -122,7 +122,7 @@ 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 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 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 integer field 0 with value 7 is transmitted as unsigned delta = 1, unsigned value
= 7 or (01 0E). Finally, after all the fields have been sent a terminating mark = 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 denotes the end of the struct. That mark is a delta=0 value, which has
representation (00). representation (00).
@ -148,7 +148,7 @@ pair (-type id, encoded-type) where encoded-type is the gob encoding of a wireTy
description, constructed from these types: description, constructed from these types:
type wireType struct { type wireType struct {
s structType; s structType
} }
type arrayType struct { type arrayType struct {
commonType commonType
@ -156,20 +156,20 @@ description, constructed from these types:
Len int Len int
} }
type commonType { type commonType {
name string; // the name of the struct type name string // the name of the struct type
id int; // the id of the type, repeated for so it's inside the type _id int // the id of the type, repeated for so it's inside the type
} }
type sliceType struct { type sliceType struct {
commonType commonType
Elem typeId Elem typeId
} }
type structType struct { type structType struct {
commonType; commonType
field []fieldType; // the fields of the struct. field []*fieldType // the fields of the struct.
} }
type fieldType struct { type fieldType struct {
name string; // the name of the field. name string // the name of the field.
id int; // the type id of the field, which must be already defined id int // the type id of the field, which must be already defined
} }
type mapType struct { type mapType struct {
commonType commonType
@ -212,13 +212,13 @@ package gob
/* /*
For implementers and the curious, here is an encoded example. Given For implementers and the curious, here is an encoded example. Given
type Point {x, y int} type Point struct {x, y int}
and the value and the value
p := Point{22, 33} p := Point{22, 33}
the bytes transmitted that encode p will be: the bytes transmitted that encode p will be:
1f ff 81 03 01 01 05 50 6f 69 6e 74 01 ff 82 00 01 02 01 01 78 1f ff 81 03 01 01 05 50 6f 69 6e 74 01 ff 82 00
01 04 00 01 01 79 01 04 00 00 00 07 ff 82 01 2c 01 42 00 07 ff 01 02 01 01 78 01 04 00 01 01 79 01 04 00 00 00
82 01 2c 01 42 00 07 ff 82 01 2c 01 42 00
They are determined as follows. They are determined as follows.
Since this is the first transmission of type Point, the type descriptor Since this is the first transmission of type Point, the type descriptor
@ -237,42 +237,42 @@ reserved).
// all its components), so we just need to send a *value* of type wireType // all its components), so we just need to send a *value* of type wireType
// that represents type "Point". // that represents type "Point".
// Here starts the encoding of that value. // Here starts the encoding of that value.
// Set the field number implicitly to zero; this is done at the beginning // Set the field number implicitly to -1; this is done at the beginning
// of every struct, including nested structs. // of every struct, including nested structs.
03 // Add 3 to field number; now 3 (wireType.structType; this is a struct). 03 // Add 3 to field number; now 2 (wireType.structType; this is a struct).
// structType starts with an embedded commonType, which appears // structType starts with an embedded commonType, which appears
// as a regular structure here too. // as a regular structure here too.
01 // add 1 to field number (now 1); start of embedded commonType. 01 // add 1 to field number (now 0); start of embedded commonType.
01 // add one to field number (now 1, the name of the type) 01 // add 1 to field number (now 0, the name of the type)
05 // string is (unsigned) 5 bytes long 05 // string is (unsigned) 5 bytes long
50 6f 69 6e 74 // wireType.structType.commonType.name = "Point" 50 6f 69 6e 74 // wireType.structType.commonType.name = "Point"
01 // add one to field number (now 2, the id of the type) 01 // add 1 to field number (now 1, the id of the type)
ff 82 // wireType.structType.commonType._id = 65 ff 82 // wireType.structType.commonType._id = 65
00 // end of embedded wiretype.structType.commonType struct 00 // end of embedded wiretype.structType.commonType struct
01 // add one to field number (now 2, the Field array in wireType.structType) 01 // add 1 to field number (now 1, the field array in wireType.structType)
02 // There are two fields in the type (len(structType.field)) 02 // There are two fields in the type (len(structType.field))
01 // Start of first field structure; add 1 to get field number 1: field[0].name 01 // Start of first field structure; add 1 to get field number 0: field[0].name
01 // 1 byte 01 // 1 byte
78 // structType.field[0].name = "x" 78 // structType.field[0].name = "x"
01 // Add 1 to get field number 2: field[0].id 01 // Add 1 to get field number 1: field[0].id
04 // structType.field[0].typeId is 2 (signed int). 04 // structType.field[0].typeId is 2 (signed int).
00 // End of structType.field[0]; start structType.field[1]; set field number to 0. 00 // End of structType.field[0]; start structType.field[1]; set field number to -1.
01 // Add 1 to get field number 1: field[1].name 01 // Add 1 to get field number 0: field[1].name
01 // 1 byte 01 // 1 byte
79 // structType.field[1].name = "y" 79 // structType.field[1].name = "y"
01 // Add 1 to get field number 2: field[0].id 01 // Add 1 to get field number 1: field[0].id
04 // struct.Type.field[1].typeId is 2 (signed int). 04 // struct.Type.field[1].typeId is 2 (signed int).
00 // End of structType.field[1]; end of structType.field. 00 // End of structType.field[1]; end of structType.field.
00 // end of wireType.structType structure 00 // end of wireType.structType structure
00 // end of wireType structure 00 // end of wireType structure
Now we can send the Point value. Again the field number resets to zero: Now we can send the Point value. Again the field number resets to -1:
07 // this value is 7 bytes long 07 // this value is 7 bytes long
ff 82 // the type number, 65 (1 byte (-FF) followed by 65<<1) ff 82 // the type number, 65 (1 byte (-FF) followed by 65<<1)
01 // add one to field number, yielding field 1 01 // add one to field number, yielding field 0
2c // encoding of signed "22" (0x22 = 44 = 22<<1); Point.x = 22 2c // encoding of signed "22" (0x22 = 44 = 22<<1); Point.x = 22
01 // add one to field number, yielding field 2 01 // add one to field number, yielding field 1
42 // encoding of signed "33" (0x42 = 66 = 33<<1); Point.y = 33 42 // encoding of signed "33" (0x42 = 66 = 33<<1); Point.y = 33
00 // end of structure 00 // end of structure