~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/pkg/gob/doc.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
convert between gobs and actual Go values.  For instance, a gob type that is
30
30
schematically,
31
31
 
32
 
        struct { a, b int }
 
32
        struct { A, B int }
33
33
 
34
34
can be sent from or received into any of these Go types:
35
35
 
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
40
40
 
41
41
It may also be received into any of these:
42
42
 
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.
48
48
 
49
49
Attempting to receive into these types will draw a decode error:
50
50
 
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
55
55
 
56
56
Integers are transmitted two ways: arbitrary precision signed integers or
57
57
arbitrary precision unsigned integers.  There is no int8, int16 etc.
269
269
 
270
270
/*
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}
273
273
and the value
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.
280
280
 
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
312
312
        01      // 1 byte
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
318
318
        01      // 1 byte
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.