29
29
convert between gobs and actual Go values. For instance, a gob type that is
34
34
can be sent from or received into any of these Go types:
36
struct { a, b int } // the same
37
*struct { a, b int } // extra indirection of the struct
38
struct { *a, **b int } // extra indirection of the fields
39
struct { a, b int64 } // different concrete value type; see below
36
struct { A, B int } // the same
37
*struct { A, B int } // extra indirection of the struct
38
struct { *A, **B int } // extra indirection of the fields
39
struct { A, B int64 } // different concrete value type; see below
41
41
It may also be received into any of these:
43
struct { a, b int } // the same
44
struct { b, a int } // ordering doesn't matter; matching is by name
45
struct { a, b, c int } // extra field (c) ignored
46
struct { b int } // missing field (a) ignored; data will be dropped
47
struct { b, c int } // missing field (a) ignored; extra field (c) ignored.
43
struct { A, B int } // the same
44
struct { B, A int } // ordering doesn't matter; matching is by name
45
struct { A, B, C int } // extra field (C) ignored
46
struct { B int } // missing field (A) ignored; data will be dropped
47
struct { B, C int } // missing field (A) ignored; extra field (C) ignored.
49
49
Attempting to receive into these types will draw a decode error:
51
struct { a int; b uint } // change of signedness for b
52
struct { a int; b float } // change of type for b
51
struct { A int; B uint } // change of signedness for B
52
struct { A int; B float } // change of type for B
53
53
struct { } // no field names in common
54
struct { c, d int } // no field names in common
54
struct { C, D int } // no field names in common
56
56
Integers are transmitted two ways: arbitrary precision signed integers or
57
57
arbitrary precision unsigned integers. There is no int8, int16 etc.
271
271
For implementers and the curious, here is an encoded example. Given
272
type Point struct {x, y int}
272
type Point struct {X, Y int}
274
274
p := Point{22, 33}
275
275
the bytes transmitted that encode p will be:
276
276
1f ff 81 03 01 01 05 50 6f 69 6e 74 01 ff 82 00
277
01 02 01 01 78 01 04 00 01 01 79 01 04 00 00 00
277
01 02 01 01 58 01 04 00 01 01 59 01 04 00 00 00
278
278
07 ff 82 01 2c 01 42 00
279
279
They are determined as follows.
310
310
02 // There are two fields in the type (len(structType.field))
311
311
01 // Start of first field structure; add 1 to get field number 0: field[0].name
313
78 // structType.field[0].name = "x"
313
58 // structType.field[0].name = "X"
314
314
01 // Add 1 to get field number 1: field[0].id
315
315
04 // structType.field[0].typeId is 2 (signed int).
316
316
00 // End of structType.field[0]; start structType.field[1]; set field number to -1.
317
317
01 // Add 1 to get field number 0: field[1].name
319
79 // structType.field[1].name = "y"
319
59 // structType.field[1].name = "Y"
320
320
01 // Add 1 to get field number 1: field[0].id
321
321
04 // struct.Type.field[1].typeId is 2 (signed int).
322
322
00 // End of structType.field[1]; end of structType.field.