LEFT | RIGHT |
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 package gob | 5 package gob |
6 | 6 |
7 // TODO(rsc): When garbage collector changes, revisit | 7 // TODO(rsc): When garbage collector changes, revisit |
8 // the allocations in this file that use unsafe.Pointer. | 8 // the allocations in this file that use unsafe.Pointer. |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 func overflow(name string) error { | 57 func overflow(name string) error { |
58 return errors.New(`value for "` + name + `" out of range`) | 58 return errors.New(`value for "` + name + `" out of range`) |
59 } | 59 } |
60 | 60 |
61 // decodeUintReader reads an encoded unsigned integer from an io.Reader. | 61 // decodeUintReader reads an encoded unsigned integer from an io.Reader. |
62 // Used only by the Decoder to read the message length. | 62 // Used only by the Decoder to read the message length. |
63 func decodeUintReader(r io.Reader, buf []byte) (x uint64, width int, err error)
{ | 63 func decodeUintReader(r io.Reader, buf []byte) (x uint64, width int, err error)
{ |
64 width = 1 | 64 width = 1 |
65 n, err := io.ReadFull(r, buf[0:width]) | 65 n, err := io.ReadFull(r, buf[0:width]) |
66 » if n < 1 { | 66 » if n == 0 { |
67 » » if err == nil { | |
68 » » » err = io.EOF | |
69 » » } | |
70 return | 67 return |
71 } | 68 } |
72 b := buf[0] | 69 b := buf[0] |
73 if b <= 0x7f { | 70 if b <= 0x7f { |
74 return uint64(b), width, nil | 71 return uint64(b), width, nil |
75 } | 72 } |
76 n = -int(int8(b)) | 73 n = -int(int8(b)) |
77 if n > uint64Size { | 74 if n > uint64Size { |
78 err = errBadUint | 75 err = errBadUint |
79 return | 76 return |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 return x.UnsafeAddr() | 1293 return x.UnsafeAddr() |
1297 } | 1294 } |
1298 | 1295 |
1299 // Gob depends on being able to take the address | 1296 // Gob depends on being able to take the address |
1300 // of zeroed Values it creates, so use this wrapper instead | 1297 // of zeroed Values it creates, so use this wrapper instead |
1301 // of the standard reflect.Zero. | 1298 // of the standard reflect.Zero. |
1302 // Each call allocates once. | 1299 // Each call allocates once. |
1303 func allocValue(t reflect.Type) reflect.Value { | 1300 func allocValue(t reflect.Type) reflect.Value { |
1304 return reflect.New(t).Elem() | 1301 return reflect.New(t).Elem() |
1305 } | 1302 } |
LEFT | RIGHT |