Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(701)

Delta Between Two Patch Sets: src/pkg/encoding/gob/doc.go

Issue 12681044: code review 12681044: encoding/gob: support new generic interfaces in package... (Closed)
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: diff -r 00b5a40ae411 https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/encoding/gob/decode.go ('k') | src/pkg/encoding/gob/encode.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 Package gob manages streams of gobs - binary values exchanged between an 6 Package gob manages streams of gobs - binary values exchanged between an
7 Encoder (transmitter) and a Decoder (receiver). A typical use is transporting 7 Encoder (transmitter) and a Decoder (receiver). A typical use is transporting
8 arguments and results of remote procedure calls (RPCs) such as those provided by 8 arguments and results of remote procedure calls (RPCs) such as those provided by
9 package "rpc". 9 package "rpc".
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 the receiver accepts the value and stores it in the destination variable. 60 the receiver accepts the value and stores it in the destination variable.
61 Floating-point numbers are always sent using IEEE-754 64-bit precision (see 61 Floating-point numbers are always sent using IEEE-754 64-bit precision (see
62 below). 62 below).
63 63
64 Signed integers may be received into any signed integer variable: int, int16, et c.; 64 Signed integers may be received into any signed integer variable: int, int16, et c.;
65 unsigned integers may be received into any unsigned integer variable; and floati ng 65 unsigned integers may be received into any unsigned integer variable; and floati ng
66 point values may be received into any floating point variable. However, 66 point values may be received into any floating point variable. However,
67 the destination variable must be able to represent the value or the decode 67 the destination variable must be able to represent the value or the decode
68 operation will fail. 68 operation will fail.
69 69
70 Structs, arrays and slices are also supported. Structs encode and 70 Structs, arrays and slices are also supported. Structs encode and decode only
71 decode only exported fields. Strings and arrays of bytes are supported 71 exported fields. Strings and arrays of bytes are supported with a special,
72 with a special, efficient representation (see below). When a slice 72 efficient representation (see below). When a slice is decoded, if the existing
73 is decoded, if the existing slice has capacity the slice will be 73 slice has capacity the slice will be extended in place; if not, a new array is
74 extended in place; if not, a new array is allocated. Regardless, 74 allocated. Regardless, the length of the resulting slice reports the number of
75 the length of the resulting slice reports the number of elements 75 elements decoded.
76 decoded. 76
77 77 Functions and channels cannot be sent in a gob. Attempting to encode a value
78 Functions and channels cannot be sent in a gob. Attempting 78 that contains one will fail.
79 to encode a value that contains one will fail. 79
80 80 Gob can encode a value of any type implementing the GobEncoder,
81 The rest of this comment documents the encoding, details that are not important 81 encoding.BinaryMarshaler, or encoding.TextMarshaler interfaces by calling the
82 for most users. Details are presented bottom-up. 82 corresponding method, in that order of preference.
83
84 Gob can decode a value of any type implementing the GobDecoder,
85 encoding.BinaryUnmarshaler, or encoding.TextUnmarshaler interfaces by calling
86 the corresponding method, again in that order of preference.
87
88 Encoding Details
89
90 This section documents the encoding, details that are not important for most
91 users. Details are presented bottom-up.
83 92
84 An unsigned integer is sent one of two ways. If it is less than 128, it is sent 93 An unsigned integer is sent one of two ways. If it is less than 128, it is sent
85 as a byte with that value. Otherwise it is sent as a minimal-length big-endian 94 as a byte with that value. Otherwise it is sent as a minimal-length big-endian
86 (high byte first) byte stream holding the value, preceded by one byte holding th e 95 (high byte first) byte stream holding the value, preceded by one byte holding th e
87 byte count, negated. Thus 0 is transmitted as (00), 7 is transmitted as (07) an d 96 byte count, negated. Thus 0 is transmitted as (00), 7 is transmitted as (07) an d
88 256 is transmitted as (FE 01 00). 97 256 is transmitted as (FE 01 00).
89 98
90 A boolean is encoded within an unsigned integer: 0 for false, 1 for true. 99 A boolean is encoded within an unsigned integer: 0 for false, 1 for true.
91 100
92 A signed integer, i, is encoded within an unsigned integer, u. Within u, bits 1 101 A signed integer, i, is encoded within an unsigned integer, u. Within u, bits 1
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 03 04 00 06 368 03 04 00 06
360 369
361 Which represents: 370 Which represents:
362 371
363 03 // this value is 3 bytes long 372 03 // this value is 3 bytes long
364 04 // the type number, 2, represents an integer 373 04 // the type number, 2, represents an integer
365 00 // tag delta 0 374 00 // tag delta 0
366 06 // value 3 375 06 // value 3
367 376
368 */ 377 */
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b