| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 1 | // Go support for Protocol Buffers - Google's data interchange format |
| 2 | // |
| David Symonds | ee6e9c5 | 2012-11-29 08:51:07 +1100 | [diff] [blame^] | 3 | // Copyright 2010 The Go Authors. All rights reserved. |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 4 | // http://code.google.com/p/goprotobuf/ |
| 5 | // |
| 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
| 9 | // |
| 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | package proto |
| 33 | |
| 34 | /* |
| 35 | * Routines for decoding protocol buffer data to construct in-memory representations. |
| 36 | */ |
| 37 | |
| 38 | import ( |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 39 | "errors" |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 40 | "fmt" |
| 41 | "io" |
| 42 | "os" |
| 43 | "reflect" |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | // ErrWrongType occurs when the wire encoding for the field disagrees with |
| 47 | // that specified in the type being decoded. This is usually caused by attempting |
| 48 | // to convert an encoded protocol buffer into a struct of the wrong type. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 49 | var ErrWrongType = errors.New("field/encoding mismatch: wrong type for field") |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 50 | |
| 51 | // The fundamental decoders that interpret bytes on the wire. |
| 52 | // Those that take integer types all return uint64 and are |
| 53 | // therefore of type valueDecoder. |
| 54 | |
| 55 | // DecodeVarint reads a varint-encoded integer from the slice. |
| 56 | // It returns the integer and the number of bytes consumed, or |
| 57 | // zero if there is not enough. |
| 58 | // This is the format for the |
| 59 | // int32, int64, uint32, uint64, bool, and enum |
| 60 | // protocol buffer types. |
| 61 | func DecodeVarint(buf []byte) (x uint64, n int) { |
| 62 | // x, n already 0 |
| 63 | for shift := uint(0); ; shift += 7 { |
| 64 | if n >= len(buf) { |
| 65 | return 0, 0 |
| 66 | } |
| 67 | b := uint64(buf[n]) |
| 68 | n++ |
| 69 | x |= (b & 0x7F) << shift |
| 70 | if (b & 0x80) == 0 { |
| 71 | break |
| 72 | } |
| 73 | } |
| 74 | return x, n |
| 75 | } |
| 76 | |
| 77 | // DecodeVarint reads a varint-encoded integer from the Buffer. |
| 78 | // This is the format for the |
| 79 | // int32, int64, uint32, uint64, bool, and enum |
| 80 | // protocol buffer types. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 81 | func (p *Buffer) DecodeVarint() (x uint64, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 82 | // x, err already 0 |
| 83 | |
| 84 | i := p.index |
| 85 | l := len(p.buf) |
| 86 | |
| 87 | for shift := uint(0); ; shift += 7 { |
| 88 | if i >= l { |
| 89 | err = io.ErrUnexpectedEOF |
| 90 | return |
| 91 | } |
| 92 | b := p.buf[i] |
| 93 | i++ |
| 94 | x |= (uint64(b) & 0x7F) << shift |
| 95 | if b < 0x80 { |
| 96 | break |
| 97 | } |
| 98 | } |
| 99 | p.index = i |
| 100 | return |
| 101 | } |
| 102 | |
| 103 | // DecodeFixed64 reads a 64-bit integer from the Buffer. |
| 104 | // This is the format for the |
| 105 | // fixed64, sfixed64, and double protocol buffer types. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 106 | func (p *Buffer) DecodeFixed64() (x uint64, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 107 | // x, err already 0 |
| 108 | i := p.index + 8 |
| 109 | if i > len(p.buf) { |
| 110 | err = io.ErrUnexpectedEOF |
| 111 | return |
| 112 | } |
| 113 | p.index = i |
| 114 | |
| 115 | x = uint64(p.buf[i-8]) |
| 116 | x |= uint64(p.buf[i-7]) << 8 |
| 117 | x |= uint64(p.buf[i-6]) << 16 |
| 118 | x |= uint64(p.buf[i-5]) << 24 |
| 119 | x |= uint64(p.buf[i-4]) << 32 |
| 120 | x |= uint64(p.buf[i-3]) << 40 |
| 121 | x |= uint64(p.buf[i-2]) << 48 |
| 122 | x |= uint64(p.buf[i-1]) << 56 |
| 123 | return |
| 124 | } |
| 125 | |
| 126 | // DecodeFixed32 reads a 32-bit integer from the Buffer. |
| 127 | // This is the format for the |
| 128 | // fixed32, sfixed32, and float protocol buffer types. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 129 | func (p *Buffer) DecodeFixed32() (x uint64, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 130 | // x, err already 0 |
| 131 | i := p.index + 4 |
| 132 | if i > len(p.buf) { |
| 133 | err = io.ErrUnexpectedEOF |
| 134 | return |
| 135 | } |
| 136 | p.index = i |
| 137 | |
| 138 | x = uint64(p.buf[i-4]) |
| 139 | x |= uint64(p.buf[i-3]) << 8 |
| 140 | x |= uint64(p.buf[i-2]) << 16 |
| 141 | x |= uint64(p.buf[i-1]) << 24 |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | // DecodeZigzag64 reads a zigzag-encoded 64-bit integer |
| 146 | // from the Buffer. |
| 147 | // This is the format used for the sint64 protocol buffer type. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 148 | func (p *Buffer) DecodeZigzag64() (x uint64, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 149 | x, err = p.DecodeVarint() |
| 150 | if err != nil { |
| 151 | return |
| 152 | } |
| 153 | x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63) |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | // DecodeZigzag32 reads a zigzag-encoded 32-bit integer |
| 158 | // from the Buffer. |
| 159 | // This is the format used for the sint32 protocol buffer type. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 160 | func (p *Buffer) DecodeZigzag32() (x uint64, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 161 | x, err = p.DecodeVarint() |
| 162 | if err != nil { |
| 163 | return |
| 164 | } |
| 165 | x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31)) |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | // These are not ValueDecoders: they produce an array of bytes or a string. |
| 170 | // bytes, embedded messages |
| 171 | |
| 172 | // DecodeRawBytes reads a count-delimited byte buffer from the Buffer. |
| 173 | // This is the format used for the bytes protocol buffer |
| 174 | // type and for embedded messages. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 175 | func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 176 | n, err := p.DecodeVarint() |
| 177 | if err != nil { |
| 178 | return |
| 179 | } |
| 180 | |
| 181 | nb := int(n) |
| David Symonds | 22ac150 | 2012-01-18 12:37:12 +1100 | [diff] [blame] | 182 | if nb < 0 { |
| 183 | return nil, fmt.Errorf("proto: bad byte length %d", nb) |
| 184 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 185 | if p.index+nb > len(p.buf) { |
| David Symonds | 22ac150 | 2012-01-18 12:37:12 +1100 | [diff] [blame] | 186 | return nil, io.ErrUnexpectedEOF |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | if !alloc { |
| 190 | // todo: check if can get more uses of alloc=false |
| 191 | buf = p.buf[p.index : p.index+nb] |
| 192 | p.index += nb |
| 193 | return |
| 194 | } |
| 195 | |
| 196 | buf = make([]byte, nb) |
| 197 | copy(buf, p.buf[p.index:]) |
| 198 | p.index += nb |
| 199 | return |
| 200 | } |
| 201 | |
| 202 | // DecodeStringBytes reads an encoded string from the Buffer. |
| 203 | // This is the format used for the proto2 string type. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 204 | func (p *Buffer) DecodeStringBytes() (s string, err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 205 | buf, err := p.DecodeRawBytes(false) |
| 206 | if err != nil { |
| 207 | return |
| 208 | } |
| 209 | return string(buf), nil |
| 210 | } |
| 211 | |
| 212 | // Skip the next item in the buffer. Its wire type is decoded and presented as an argument. |
| 213 | // If the protocol buffer has extensions, and the field matches, add it as an extension. |
| 214 | // Otherwise, if the XXX_unrecognized field exists, append the skipped data there. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 215 | func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base structPointer, unrecField field) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 216 | |
| 217 | oi := o.index |
| 218 | |
| 219 | err := o.skip(t, tag, wire) |
| 220 | if err != nil { |
| 221 | return err |
| 222 | } |
| 223 | |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 224 | if !unrecField.IsValid() { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 225 | return nil |
| 226 | } |
| 227 | |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 228 | ptr := structPointer_Bytes(base, unrecField) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 229 | |
| 230 | if *ptr == nil { |
| 231 | // This is the first skipped element, |
| 232 | // allocate a new buffer. |
| 233 | *ptr = o.bufalloc() |
| 234 | } |
| 235 | |
| 236 | // Add the skipped field to struct field |
| 237 | obuf := o.buf |
| 238 | |
| 239 | o.buf = *ptr |
| 240 | o.EncodeVarint(uint64(tag<<3 | wire)) |
| Rob Pike | 99fa2b6 | 2010-12-02 10:39:42 -0800 | [diff] [blame] | 241 | *ptr = append(o.buf, obuf[oi:o.index]...) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 242 | |
| 243 | o.buf = obuf |
| 244 | |
| 245 | return nil |
| 246 | } |
| 247 | |
| 248 | // Skip the next item in the buffer. Its wire type is decoded and presented as an argument. |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 249 | func (o *Buffer) skip(t reflect.Type, tag, wire int) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 250 | |
| 251 | var u uint64 |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 252 | var err error |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 253 | |
| 254 | switch wire { |
| 255 | case WireVarint: |
| 256 | _, err = o.DecodeVarint() |
| 257 | case WireFixed64: |
| 258 | _, err = o.DecodeFixed64() |
| 259 | case WireBytes: |
| 260 | _, err = o.DecodeRawBytes(false) |
| 261 | case WireFixed32: |
| 262 | _, err = o.DecodeFixed32() |
| 263 | case WireStartGroup: |
| 264 | for { |
| 265 | u, err = o.DecodeVarint() |
| 266 | if err != nil { |
| 267 | break |
| 268 | } |
| 269 | fwire := int(u & 0x7) |
| 270 | if fwire == WireEndGroup { |
| 271 | break |
| 272 | } |
| 273 | ftag := int(u >> 3) |
| 274 | err = o.skip(t, ftag, fwire) |
| 275 | if err != nil { |
| 276 | break |
| 277 | } |
| 278 | } |
| 279 | default: |
| David Symonds | 22ac150 | 2012-01-18 12:37:12 +1100 | [diff] [blame] | 280 | err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 281 | } |
| 282 | return err |
| 283 | } |
| 284 | |
| David Symonds | 7d3c680 | 2012-11-08 08:20:18 +1100 | [diff] [blame] | 285 | // Unmarshaler is the interface representing objects that can |
| 286 | // unmarshal themselves. The method should reset the receiver before |
| 287 | // decoding starts. The argument points to data that may be |
| 288 | // overwritten, so implementations should not keep references to the |
| 289 | // buffer. |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 290 | type Unmarshaler interface { |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 291 | Unmarshal([]byte) error |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // Unmarshal parses the protocol buffer representation in buf and places the |
| 295 | // decoded result in pb. If the struct underlying pb does not match |
| 296 | // the data in buf, the results can be unpredictable. |
| David Symonds | 1928560 | 2012-07-02 16:04:28 -0700 | [diff] [blame] | 297 | // |
| David Symonds | 525838c | 2012-07-20 15:42:49 +1000 | [diff] [blame] | 298 | // Unmarshal resets pb before starting to unmarshal, so any |
| 299 | // existing data in pb is always removed. Use UnmarshalAppend |
| 300 | // to preserve and append to existing data. |
| David Symonds | 9f60f43 | 2012-06-14 09:45:25 +1000 | [diff] [blame] | 301 | func Unmarshal(buf []byte, pb Message) error { |
| David Symonds | 525838c | 2012-07-20 15:42:49 +1000 | [diff] [blame] | 302 | pb.Reset() |
| David Symonds | 1928560 | 2012-07-02 16:04:28 -0700 | [diff] [blame] | 303 | return UnmarshalAppend(buf, pb) |
| 304 | } |
| 305 | |
| 306 | // UnmarshalAppend parses the protocol buffer representation in buf and |
| 307 | // writes the decoded result to pb. If the struct underlying pb does not match |
| 308 | // the data in buf, the results can be unpredictable. |
| 309 | // |
| David Symonds | 525838c | 2012-07-20 15:42:49 +1000 | [diff] [blame] | 310 | // UnmarshalAppend preserves and appends to existing data in pb. |
| 311 | // Most code should use Unmarshal instead. |
| David Symonds | 1928560 | 2012-07-02 16:04:28 -0700 | [diff] [blame] | 312 | func UnmarshalAppend(buf []byte, pb Message) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 313 | // If the object can unmarshal itself, let it. |
| 314 | if u, ok := pb.(Unmarshaler); ok { |
| 315 | return u.Unmarshal(buf) |
| 316 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 317 | return NewBuffer(buf).Unmarshal(pb) |
| 318 | } |
| 319 | |
| 320 | // Unmarshal parses the protocol buffer representation in the |
| 321 | // Buffer and places the decoded result in pb. If the struct |
| 322 | // underlying pb does not match the data in the buffer, the results can be |
| 323 | // unpredictable. |
| David Symonds | 9f60f43 | 2012-06-14 09:45:25 +1000 | [diff] [blame] | 324 | func (p *Buffer) Unmarshal(pb Message) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 325 | // If the object can unmarshal itself, let it. |
| 326 | if u, ok := pb.(Unmarshaler); ok { |
| 327 | err := u.Unmarshal(p.buf[p.index:]) |
| 328 | p.index = len(p.buf) |
| 329 | return err |
| 330 | } |
| 331 | |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 332 | typ, base, err := getbase(pb) |
| 333 | if err != nil { |
| 334 | return err |
| 335 | } |
| 336 | |
| David Symonds | 6a6f82c | 2012-08-22 09:18:54 +1000 | [diff] [blame] | 337 | err = p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), false, base) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 338 | |
| David Symonds | 9f60f43 | 2012-06-14 09:45:25 +1000 | [diff] [blame] | 339 | if collectStats { |
| 340 | stats.Decode++ |
| 341 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 342 | |
| 343 | return err |
| 344 | } |
| 345 | |
| 346 | // unmarshalType does the work of unmarshaling a structure. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 347 | func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group bool, base structPointer) error { |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 348 | required, reqFields := prop.reqCount, uint64(0) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 349 | |
| Rob Pike | a17fdd9 | 2011-11-02 12:43:05 -0700 | [diff] [blame] | 350 | var err error |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 351 | for err == nil && o.index < len(o.buf) { |
| 352 | oi := o.index |
| 353 | var u uint64 |
| 354 | u, err = o.DecodeVarint() |
| 355 | if err != nil { |
| 356 | break |
| 357 | } |
| 358 | wire := int(u & 0x7) |
| 359 | if wire == WireEndGroup { |
| 360 | if is_group { |
| 361 | return nil // input is satisfied |
| 362 | } |
| 363 | return ErrWrongType |
| 364 | } |
| 365 | tag := int(u >> 3) |
| David Symonds | 6e50db5 | 2012-02-11 15:56:22 +1100 | [diff] [blame] | 366 | if tag <= 0 { |
| 367 | return fmt.Errorf("proto: illegal tag %d", tag) |
| 368 | } |
| David Symonds | 2bba1b2 | 2012-09-26 14:53:08 +1000 | [diff] [blame] | 369 | fieldnum, ok := prop.decoderTags.get(tag) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 370 | if !ok { |
| 371 | // Maybe it's an extension? |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 372 | if prop.extendable { |
| 373 | if e := structPointer_Interface(base, st).(extendableProto); isExtensionField(e, int32(tag)) { |
| 374 | if err = o.skip(st, tag, wire); err == nil { |
| 375 | ext := e.ExtensionMap()[int32(tag)] // may be missing |
| 376 | ext.enc = append(ext.enc, o.buf[oi:o.index]...) |
| 377 | e.ExtensionMap()[int32(tag)] = ext |
| 378 | } |
| 379 | continue |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 380 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 381 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 382 | err = o.skipAndSave(st, tag, wire, base, prop.unrecField) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 383 | continue |
| 384 | } |
| 385 | p := prop.Prop[fieldnum] |
| 386 | |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 387 | if p.dec == nil { |
| David Symonds | 6a6f82c | 2012-08-22 09:18:54 +1000 | [diff] [blame] | 388 | fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 389 | continue |
| 390 | } |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 391 | dec := p.dec |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 392 | if wire != WireStartGroup && wire != p.WireType { |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 393 | if wire == WireBytes && p.packedDec != nil { |
| 394 | // a packable field |
| 395 | dec = p.packedDec |
| 396 | } else { |
| 397 | err = ErrWrongType |
| 398 | continue |
| 399 | } |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 400 | } |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 401 | err = dec(o, p, base) |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 402 | if err == nil && p.Required { |
| 403 | // Successfully decoded a required field. |
| 404 | if tag <= 64 { |
| 405 | // use bitmap for fields 1-64 to catch field reuse. |
| 406 | var mask uint64 = 1 << uint64(tag-1) |
| 407 | if reqFields&mask == 0 { |
| 408 | // new required field |
| 409 | reqFields |= mask |
| 410 | required-- |
| 411 | } |
| 412 | } else { |
| 413 | // This is imprecise. It can be fooled by a required field |
| 414 | // with a tag > 64 that is encoded twice; that's very rare. |
| 415 | // A fully correct implementation would require allocating |
| 416 | // a data structure, which we would like to avoid. |
| 417 | required-- |
| 418 | } |
| 419 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 420 | } |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 421 | if err == nil { |
| 422 | if is_group { |
| 423 | return io.ErrUnexpectedEOF |
| 424 | } |
| 425 | if required > 0 { |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 426 | return &ErrRequiredNotSet{st} |
| Rob Pike | c6d8e4a | 2010-07-28 15:34:32 -0700 | [diff] [blame] | 427 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 428 | } |
| 429 | return err |
| 430 | } |
| 431 | |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 432 | // Individual type decoders |
| 433 | // For each, |
| 434 | // u is the decoded value, |
| 435 | // v is a pointer to the field (pointer) in the struct |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 436 | |
| 437 | // Sizes of the pools to allocate inside the Buffer. |
| Rob Pike | 97edc7e | 2011-10-20 15:53:19 -0700 | [diff] [blame] | 438 | // The goal is modest amortization and allocation |
| 439 | // on at least 16-byte boundaries. |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 440 | const ( |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 441 | boolPoolSize = 16 |
| 442 | uint32PoolSize = 8 |
| 443 | uint64PoolSize = 4 |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 444 | ) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 445 | |
| 446 | // Decode a bool. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 447 | func (o *Buffer) dec_bool(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 448 | u, err := p.valDec(o) |
| 449 | if err != nil { |
| 450 | return err |
| 451 | } |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 452 | if len(o.bools) == 0 { |
| 453 | o.bools = make([]bool, boolPoolSize) |
| 454 | } |
| 455 | o.bools[0] = u != 0 |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 456 | *structPointer_Bool(base, p.field) = &o.bools[0] |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 457 | o.bools = o.bools[1:] |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 458 | return nil |
| 459 | } |
| 460 | |
| 461 | // Decode an int32. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 462 | func (o *Buffer) dec_int32(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 463 | u, err := p.valDec(o) |
| 464 | if err != nil { |
| 465 | return err |
| 466 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 467 | word32_Set(structPointer_Word32(base, p.field), o, uint32(u)) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 468 | return nil |
| 469 | } |
| 470 | |
| 471 | // Decode an int64. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 472 | func (o *Buffer) dec_int64(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 473 | u, err := p.valDec(o) |
| 474 | if err != nil { |
| 475 | return err |
| 476 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 477 | word64_Set(structPointer_Word64(base, p.field), o, u) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 478 | return nil |
| 479 | } |
| 480 | |
| 481 | // Decode a string. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 482 | func (o *Buffer) dec_string(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 483 | s, err := o.DecodeStringBytes() |
| 484 | if err != nil { |
| 485 | return err |
| 486 | } |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 487 | sp := new(string) |
| 488 | *sp = s |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 489 | *structPointer_String(base, p.field) = sp |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 490 | return nil |
| 491 | } |
| 492 | |
| 493 | // Decode a slice of bytes ([]byte). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 494 | func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error { |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 495 | b, err := o.DecodeRawBytes(true) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 496 | if err != nil { |
| 497 | return err |
| 498 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 499 | *structPointer_Bytes(base, p.field) = b |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 500 | return nil |
| 501 | } |
| 502 | |
| 503 | // Decode a slice of bools ([]bool). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 504 | func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 505 | u, err := p.valDec(o) |
| 506 | if err != nil { |
| 507 | return err |
| 508 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 509 | v := structPointer_BoolSlice(base, p.field) |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 510 | *v = append(*v, u != 0) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 511 | return nil |
| 512 | } |
| 513 | |
| 514 | // Decode a slice of bools ([]bool) in packed format. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 515 | func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error { |
| 516 | v := structPointer_BoolSlice(base, p.field) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 517 | |
| 518 | nn, err := o.DecodeVarint() |
| 519 | if err != nil { |
| 520 | return err |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 521 | } |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 522 | nb := int(nn) // number of bytes of encoded bools |
| 523 | |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 524 | y := *v |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 525 | for i := 0; i < nb; i++ { |
| 526 | u, err := p.valDec(o) |
| 527 | if err != nil { |
| 528 | return err |
| 529 | } |
| 530 | y = append(y, u != 0) |
| 531 | } |
| 532 | |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 533 | *v = y |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 534 | return nil |
| 535 | } |
| 536 | |
| 537 | // Decode a slice of int32s ([]int32). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 538 | func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 539 | u, err := p.valDec(o) |
| 540 | if err != nil { |
| 541 | return err |
| 542 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 543 | structPointer_Word32Slice(base, p.field).Append(uint32(u)) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 544 | return nil |
| 545 | } |
| 546 | |
| 547 | // Decode a slice of int32s ([]int32) in packed format. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 548 | func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error { |
| 549 | v := structPointer_Word32Slice(base, p.field) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 550 | |
| 551 | nn, err := o.DecodeVarint() |
| 552 | if err != nil { |
| 553 | return err |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 554 | } |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 555 | nb := int(nn) // number of bytes of encoded int32s |
| 556 | |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 557 | fin := o.index + nb |
| 558 | for o.index < fin { |
| 559 | u, err := p.valDec(o) |
| 560 | if err != nil { |
| 561 | return err |
| 562 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 563 | v.Append(uint32(u)) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 564 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 565 | return nil |
| 566 | } |
| 567 | |
| 568 | // Decode a slice of int64s ([]int64). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 569 | func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 570 | u, err := p.valDec(o) |
| 571 | if err != nil { |
| 572 | return err |
| 573 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 574 | |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 575 | structPointer_Word64Slice(base, p.field).Append(u) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 576 | return nil |
| 577 | } |
| 578 | |
| 579 | // Decode a slice of int64s ([]int64) in packed format. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 580 | func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error { |
| 581 | v := structPointer_Word64Slice(base, p.field) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 582 | |
| 583 | nn, err := o.DecodeVarint() |
| 584 | if err != nil { |
| 585 | return err |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 586 | } |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 587 | nb := int(nn) // number of bytes of encoded int64s |
| 588 | |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 589 | fin := o.index + nb |
| 590 | for o.index < fin { |
| 591 | u, err := p.valDec(o) |
| 592 | if err != nil { |
| 593 | return err |
| 594 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 595 | v.Append(u) |
| David Symonds | 5b7775e | 2010-12-01 10:09:04 +1100 | [diff] [blame] | 596 | } |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 597 | return nil |
| 598 | } |
| 599 | |
| 600 | // Decode a slice of strings ([]string). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 601 | func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 602 | s, err := o.DecodeStringBytes() |
| 603 | if err != nil { |
| 604 | return err |
| 605 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 606 | v := structPointer_StringSlice(base, p.field) |
| 607 | *v = append(*v, s) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 608 | return nil |
| 609 | } |
| 610 | |
| 611 | // Decode a slice of slice of bytes ([][]byte). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 612 | func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 613 | b, err := o.DecodeRawBytes(true) |
| 614 | if err != nil { |
| 615 | return err |
| 616 | } |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 617 | v := structPointer_BytesSlice(base, p.field) |
| 618 | *v = append(*v, b) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 619 | return nil |
| 620 | } |
| 621 | |
| 622 | // Decode a group. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 623 | func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error { |
| 624 | bas := toStructPointer(reflect.New(p.stype)) |
| 625 | structPointer_SetStructPointer(base, p.field, bas) |
| 626 | return o.unmarshalType(p.stype, p.sprop, true, bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | // Decode an embedded message. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 630 | func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) { |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 631 | raw, e := o.DecodeRawBytes(false) |
| 632 | if e != nil { |
| 633 | return e |
| 634 | } |
| 635 | |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 636 | v := reflect.New(p.stype) |
| 637 | bas := toStructPointer(v) |
| 638 | structPointer_SetStructPointer(base, p.field, bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 639 | |
| 640 | // If the object can unmarshal itself, let it. |
| David Symonds | a80b282 | 2012-03-14 14:31:25 +1100 | [diff] [blame] | 641 | if p.isMarshaler { |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 642 | iv := v.Interface() |
| David Symonds | a80b282 | 2012-03-14 14:31:25 +1100 | [diff] [blame] | 643 | return iv.(Unmarshaler).Unmarshal(raw) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | obuf := o.buf |
| 647 | oi := o.index |
| 648 | o.buf = raw |
| 649 | o.index = 0 |
| 650 | |
| David Symonds | c028717 | 2012-08-15 11:10:30 +1000 | [diff] [blame] | 651 | err = o.unmarshalType(p.stype, p.sprop, false, bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 652 | o.buf = obuf |
| 653 | o.index = oi |
| 654 | |
| 655 | return err |
| 656 | } |
| 657 | |
| 658 | // Decode a slice of embedded messages. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 659 | func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error { |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 660 | return o.dec_slice_struct(p, false, base) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | // Decode a slice of embedded groups. |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 664 | func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error { |
| Rob Pike | 76f6ee5 | 2011-10-20 12:58:28 -0700 | [diff] [blame] | 665 | return o.dec_slice_struct(p, true, base) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | // Decode a slice of structs ([]*struct). |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 669 | func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error { |
| 670 | v := reflect.New(p.stype) |
| 671 | bas := toStructPointer(v) |
| 672 | structPointer_StructPointerSlice(base, p.field).Append(bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 673 | |
| 674 | if is_group { |
| David Symonds | c028717 | 2012-08-15 11:10:30 +1000 | [diff] [blame] | 675 | err := o.unmarshalType(p.stype, p.sprop, is_group, bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 676 | return err |
| 677 | } |
| 678 | |
| David Symonds | c028717 | 2012-08-15 11:10:30 +1000 | [diff] [blame] | 679 | raw, err := o.DecodeRawBytes(false) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 680 | if err != nil { |
| 681 | return err |
| 682 | } |
| 683 | |
| 684 | // If the object can unmarshal itself, let it. |
| David Symonds | a80b282 | 2012-03-14 14:31:25 +1100 | [diff] [blame] | 685 | if p.isUnmarshaler { |
| Russ Cox | d4ce3f1 | 2012-09-12 10:36:26 +1000 | [diff] [blame] | 686 | iv := v.Interface() |
| David Symonds | a80b282 | 2012-03-14 14:31:25 +1100 | [diff] [blame] | 687 | return iv.(Unmarshaler).Unmarshal(raw) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | obuf := o.buf |
| 691 | oi := o.index |
| 692 | o.buf = raw |
| 693 | o.index = 0 |
| 694 | |
| David Symonds | c028717 | 2012-08-15 11:10:30 +1000 | [diff] [blame] | 695 | err = o.unmarshalType(p.stype, p.sprop, is_group, bas) |
| Rob Pike | aaa3a62 | 2010-03-20 22:32:34 -0700 | [diff] [blame] | 696 | |
| 697 | o.buf = obuf |
| 698 | o.index = oi |
| 699 | |
| 700 | return err |
| 701 | } |