blob: 1019d2ae393518c3efcd3923ad37eb78db58bf62 [file] [log] [blame]
Rob Pikeaaa3a622010-03-20 22:32:34 -07001// Go support for Protocol Buffers - Google's data interchange format
2//
3// Copyright 2010 Google Inc. All rights reserved.
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
32package proto
33
34/*
35 * Routines for decoding protocol buffer data to construct in-memory representations.
36 */
37
38import (
39 "bytes"
40 "fmt"
41 "io"
42 "os"
43 "reflect"
44 "runtime"
45 "unsafe"
46)
47
48// ErrWrongType occurs when the wire encoding for the field disagrees with
49// that specified in the type being decoded. This is usually caused by attempting
50// to convert an encoded protocol buffer into a struct of the wrong type.
51var ErrWrongType = os.NewError("field/encoding mismatch: wrong type for field")
52
53// The fundamental decoders that interpret bytes on the wire.
54// Those that take integer types all return uint64 and are
55// therefore of type valueDecoder.
56
57// DecodeVarint reads a varint-encoded integer from the slice.
58// It returns the integer and the number of bytes consumed, or
59// zero if there is not enough.
60// This is the format for the
61// int32, int64, uint32, uint64, bool, and enum
62// protocol buffer types.
63func DecodeVarint(buf []byte) (x uint64, n int) {
64 // x, n already 0
65 for shift := uint(0); ; shift += 7 {
66 if n >= len(buf) {
67 return 0, 0
68 }
69 b := uint64(buf[n])
70 n++
71 x |= (b & 0x7F) << shift
72 if (b & 0x80) == 0 {
73 break
74 }
75 }
76 return x, n
77}
78
79// DecodeVarint reads a varint-encoded integer from the Buffer.
80// This is the format for the
81// int32, int64, uint32, uint64, bool, and enum
82// protocol buffer types.
83func (p *Buffer) DecodeVarint() (x uint64, err os.Error) {
84 // x, err already 0
85
86 i := p.index
87 l := len(p.buf)
88
89 for shift := uint(0); ; shift += 7 {
90 if i >= l {
91 err = io.ErrUnexpectedEOF
92 return
93 }
94 b := p.buf[i]
95 i++
96 x |= (uint64(b) & 0x7F) << shift
97 if b < 0x80 {
98 break
99 }
100 }
101 p.index = i
102 return
103}
104
105// DecodeFixed64 reads a 64-bit integer from the Buffer.
106// This is the format for the
107// fixed64, sfixed64, and double protocol buffer types.
108func (p *Buffer) DecodeFixed64() (x uint64, err os.Error) {
109 // x, err already 0
110 i := p.index + 8
111 if i > len(p.buf) {
112 err = io.ErrUnexpectedEOF
113 return
114 }
115 p.index = i
116
117 x = uint64(p.buf[i-8])
118 x |= uint64(p.buf[i-7]) << 8
119 x |= uint64(p.buf[i-6]) << 16
120 x |= uint64(p.buf[i-5]) << 24
121 x |= uint64(p.buf[i-4]) << 32
122 x |= uint64(p.buf[i-3]) << 40
123 x |= uint64(p.buf[i-2]) << 48
124 x |= uint64(p.buf[i-1]) << 56
125 return
126}
127
128// DecodeFixed32 reads a 32-bit integer from the Buffer.
129// This is the format for the
130// fixed32, sfixed32, and float protocol buffer types.
131func (p *Buffer) DecodeFixed32() (x uint64, err os.Error) {
132 // x, err already 0
133 i := p.index + 4
134 if i > len(p.buf) {
135 err = io.ErrUnexpectedEOF
136 return
137 }
138 p.index = i
139
140 x = uint64(p.buf[i-4])
141 x |= uint64(p.buf[i-3]) << 8
142 x |= uint64(p.buf[i-2]) << 16
143 x |= uint64(p.buf[i-1]) << 24
144 return
145}
146
147// DecodeZigzag64 reads a zigzag-encoded 64-bit integer
148// from the Buffer.
149// This is the format used for the sint64 protocol buffer type.
150func (p *Buffer) DecodeZigzag64() (x uint64, err os.Error) {
151 x, err = p.DecodeVarint()
152 if err != nil {
153 return
154 }
155 x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63)
156 return
157}
158
159// DecodeZigzag32 reads a zigzag-encoded 32-bit integer
160// from the Buffer.
161// This is the format used for the sint32 protocol buffer type.
162func (p *Buffer) DecodeZigzag32() (x uint64, err os.Error) {
163 x, err = p.DecodeVarint()
164 if err != nil {
165 return
166 }
167 x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31))
168 return
169}
170
171// These are not ValueDecoders: they produce an array of bytes or a string.
172// bytes, embedded messages
173
174// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
175// This is the format used for the bytes protocol buffer
176// type and for embedded messages.
177func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err os.Error) {
178 n, err := p.DecodeVarint()
179 if err != nil {
180 return
181 }
182
183 nb := int(n)
184 if p.index+nb > len(p.buf) {
185 err = io.ErrUnexpectedEOF
186 return
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.
204func (p *Buffer) DecodeStringBytes() (s string, err os.Error) {
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.
215func (o *Buffer) skipAndSave(t *reflect.StructType, tag, wire int, base uintptr) os.Error {
216
217 oi := o.index
218
219 err := o.skip(t, tag, wire)
220 if err != nil {
221 return err
222 }
223
224 x := fieldIndex(t, "XXX_unrecognized")
225 if x == nil {
226 return nil
227 }
228
229 p := propByIndex(t, x)
230 ptr := (*[]byte)(unsafe.Pointer(base + p.offset))
231
232 if *ptr == nil {
233 // This is the first skipped element,
234 // allocate a new buffer.
235 *ptr = o.bufalloc()
236 }
237
238 // Add the skipped field to struct field
239 obuf := o.buf
240
241 o.buf = *ptr
242 o.EncodeVarint(uint64(tag<<3 | wire))
243 *ptr = bytes.Add(o.buf, obuf[oi:o.index])
244
245 o.buf = obuf
246
247 return nil
248}
249
250// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
251func (o *Buffer) skip(t *reflect.StructType, tag, wire int) os.Error {
252
253 var u uint64
254 var err os.Error
255
256 switch wire {
257 case WireVarint:
258 _, err = o.DecodeVarint()
259 case WireFixed64:
260 _, err = o.DecodeFixed64()
261 case WireBytes:
262 _, err = o.DecodeRawBytes(false)
263 case WireFixed32:
264 _, err = o.DecodeFixed32()
265 case WireStartGroup:
266 for {
267 u, err = o.DecodeVarint()
268 if err != nil {
269 break
270 }
271 fwire := int(u & 0x7)
272 if fwire == WireEndGroup {
273 break
274 }
275 ftag := int(u >> 3)
276 err = o.skip(t, ftag, fwire)
277 if err != nil {
278 break
279 }
280 }
281 default:
282 fmt.Fprintf(os.Stderr, "proto: can't skip wire type %d for %s\n", wire, t)
283 }
284 return err
285}
286
287// Unmarshaler is the interface representing objects that can unmarshal themselves.
288type Unmarshaler interface {
289 Unmarshal([]byte) os.Error
290}
291
292// Unmarshal parses the protocol buffer representation in buf and places the
293// decoded result in pb. If the struct underlying pb does not match
294// the data in buf, the results can be unpredictable.
295func Unmarshal(buf []byte, pb interface{}) os.Error {
296 // If the object can unmarshal itself, let it.
297 if u, ok := pb.(Unmarshaler); ok {
298 return u.Unmarshal(buf)
299 }
300
301 return NewBuffer(buf).Unmarshal(pb)
302}
303
304// Unmarshal parses the protocol buffer representation in the
305// Buffer and places the decoded result in pb. If the struct
306// underlying pb does not match the data in the buffer, the results can be
307// unpredictable.
308func (p *Buffer) Unmarshal(pb interface{}) os.Error {
309 // If the object can unmarshal itself, let it.
310 if u, ok := pb.(Unmarshaler); ok {
311 err := u.Unmarshal(p.buf[p.index:])
312 p.index = len(p.buf)
313 return err
314 }
315
316 mstat := runtime.MemStats.Mallocs
317
318 typ, base, err := getbase(pb)
319 if err != nil {
320 return err
321 }
322
323 err = p.unmarshalType(typ, false, base)
324
325 mstat = runtime.MemStats.Mallocs - mstat
326 stats.Dmalloc += mstat
327 stats.Decode++
328
329 return err
330}
331
332// unmarshalType does the work of unmarshaling a structure.
333func (o *Buffer) unmarshalType(t *reflect.PtrType, is_group bool, base uintptr) os.Error {
334 st := t.Elem().(*reflect.StructType)
335 prop := GetProperties(st)
Rob Pikec6d8e4a2010-07-28 15:34:32 -0700336 required, reqFields := prop.reqCount, uint64(0)
Rob Pikeaaa3a622010-03-20 22:32:34 -0700337 sbase := getsbase(prop) // scratch area for data items
338
339 var err os.Error
340 for err == nil && o.index < len(o.buf) {
341 oi := o.index
342 var u uint64
343 u, err = o.DecodeVarint()
344 if err != nil {
345 break
346 }
347 wire := int(u & 0x7)
348 if wire == WireEndGroup {
349 if is_group {
350 return nil // input is satisfied
351 }
352 return ErrWrongType
353 }
354 tag := int(u >> 3)
355 fieldnum, ok := prop.tags[tag]
356 if !ok {
357 // Maybe it's an extension?
358 o.ptr = base
359 iv := unsafe.Unreflect(t, unsafe.Pointer(&o.ptr))
360 if e, ok := iv.(extendableProto); ok && isExtensionField(e, int32(tag)) {
361 if err = o.skip(st, tag, wire); err == nil {
362 e.ExtensionMap()[int32(tag)] = bytes.Add(nil, o.buf[oi:o.index])
363 }
364 continue
365 }
366 err = o.skipAndSave(st, tag, wire, base)
367 continue
368 }
369 p := prop.Prop[fieldnum]
370
Rob Pikec6d8e4a2010-07-28 15:34:32 -0700371 if p.dec == nil {
372 fmt.Fprintf(os.Stderr, "no protobuf decoder for %s.%s\n", t, st.Field(fieldnum).Name)
Rob Pikeaaa3a622010-03-20 22:32:34 -0700373 continue
374 }
Rob Pikec6d8e4a2010-07-28 15:34:32 -0700375 if wire != WireStartGroup && wire != p.WireType {
376 err = ErrWrongType
377 continue
378 }
379 err = p.dec(o, p, base, sbase)
380 if err == nil && p.Required {
381 // Successfully decoded a required field.
382 if tag <= 64 {
383 // use bitmap for fields 1-64 to catch field reuse.
384 var mask uint64 = 1 << uint64(tag-1)
385 if reqFields&mask == 0 {
386 // new required field
387 reqFields |= mask
388 required--
389 }
390 } else {
391 // This is imprecise. It can be fooled by a required field
392 // with a tag > 64 that is encoded twice; that's very rare.
393 // A fully correct implementation would require allocating
394 // a data structure, which we would like to avoid.
395 required--
396 }
397 }
Rob Pikeaaa3a622010-03-20 22:32:34 -0700398 }
Rob Pikec6d8e4a2010-07-28 15:34:32 -0700399 if err == nil {
400 if is_group {
401 return io.ErrUnexpectedEOF
402 }
403 if required > 0 {
404 return ErrRequiredNotSet
405 }
Rob Pikeaaa3a622010-03-20 22:32:34 -0700406 }
407 return err
408}
409
410// Make *pslice have base address base, length 0, and capacity startSize.
411func initSlice(pslice unsafe.Pointer, base uintptr) {
412 sp := (*reflect.SliceHeader)(pslice)
413 sp.Data = base
414 sp.Len = 0
415 sp.Cap = startSize
416}
417
418// Individual type decoders
419// For each,
420// u is the decoded value,
421// v is a pointer to the field (pointer) in the struct
422// x is a pointer to the preallocated scratch space to hold the decoded value.
423
424// Decode a bool.
425func (o *Buffer) dec_bool(p *Properties, base uintptr, sbase uintptr) os.Error {
426 u, err := p.valDec(o)
427 if err != nil {
428 return err
429 }
430 v := (**uint8)(unsafe.Pointer(base + p.offset))
431 x := (*uint8)(unsafe.Pointer(sbase + p.scratch))
432 *x = uint8(u)
433 *v = x
434 return nil
435}
436
437// Decode an int32.
438func (o *Buffer) dec_int32(p *Properties, base uintptr, sbase uintptr) os.Error {
439 u, err := p.valDec(o)
440 if err != nil {
441 return err
442 }
443 v := (**int32)(unsafe.Pointer(base + p.offset))
444 x := (*int32)(unsafe.Pointer(sbase + p.scratch))
445 *x = int32(u)
446 *v = x
447 return nil
448}
449
450// Decode an int64.
451func (o *Buffer) dec_int64(p *Properties, base uintptr, sbase uintptr) os.Error {
452 u, err := p.valDec(o)
453 if err != nil {
454 return err
455 }
456 v := (**int64)(unsafe.Pointer(base + p.offset))
457 x := (*int64)(unsafe.Pointer(sbase + p.scratch))
458 *x = int64(u)
459 *v = x
460 return nil
461}
462
463// Decode a string.
464func (o *Buffer) dec_string(p *Properties, base uintptr, sbase uintptr) os.Error {
465 s, err := o.DecodeStringBytes()
466 if err != nil {
467 return err
468 }
469 v := (**string)(unsafe.Pointer(base + p.offset))
470 x := (*string)(unsafe.Pointer(sbase + p.scratch))
471 *x = s
472 *v = x
473 return nil
474}
475
476// Decode a slice of bytes ([]byte).
477func (o *Buffer) dec_slice_byte(p *Properties, base uintptr, sbase uintptr) os.Error {
478 b, err := o.DecodeRawBytes(false)
479 if err != nil {
480 return err
481 }
Mikkel Krautzdb488aa2010-11-29 14:15:51 -0800482
Rob Pikeaaa3a622010-03-20 22:32:34 -0700483 x := (*[]uint8)(unsafe.Pointer(base + p.offset))
484
485 y := *x
486 c := cap(y)
487 if c == 0 {
488 initSlice(unsafe.Pointer(x), sbase+p.scratch)
489 y = *x
490 c = cap(y)
491 }
492
493 l := len(y)
Mikkel Krautzdb488aa2010-11-29 14:15:51 -0800494 lb := len(b)
Rob Pikeaaa3a622010-03-20 22:32:34 -0700495 if l+lb > c {
496 // incremental growth is max(len(slice)*1.5, len(slice)+len(bytes))
497 g := l * 3 / 2
498 if l+lb > g {
499 g = l + lb
500 }
501 z := make([]uint8, l, g)
502 copy(z, y)
503 y = z
504 }
505
506 y = y[0 : l+lb]
507 copy(y[l:l+lb], b)
508
509 *x = y
510 return nil
511}
512
513// Decode a slice of bools ([]bool).
514func (o *Buffer) dec_slice_bool(p *Properties, base uintptr, sbase uintptr) os.Error {
515 u, err := p.valDec(o)
516 if err != nil {
517 return err
518 }
519 x := (*[]bool)(unsafe.Pointer(base + p.offset))
520
521 y := *x
522 c := cap(y)
523 if c == 0 {
524 initSlice(unsafe.Pointer(x), sbase+p.scratch)
525 y = *x
526 c = cap(y)
527 }
528 l := len(y)
529 if l >= c {
530 g := l * 3 / 2
531 z := make([]bool, l, g)
532 copy(z, y)
533 y = z
534 }
535 y = y[0 : l+1]
536 y[l] = u != 0
537 *x = y
538 return nil
539}
540
541// Decode a slice of int32s ([]int32).
542func (o *Buffer) dec_slice_int32(p *Properties, base uintptr, sbase uintptr) os.Error {
543 u, err := p.valDec(o)
544 if err != nil {
545 return err
546 }
547 x := (*[]int32)(unsafe.Pointer(base + p.offset))
548
549 y := *x
550 c := cap(y)
551 if c == 0 {
552 initSlice(unsafe.Pointer(x), sbase+p.scratch)
553 y = *x
554 c = cap(y)
555 }
556 l := len(y)
557 if l >= c {
558 g := l * 3 / 2
559 z := make([]int32, l, g)
560 copy(z, y)
561 y = z
562 }
563 y = y[0 : l+1]
564 y[l] = int32(u)
565 *x = y
566 return nil
567}
568
569// Decode a slice of int64s ([]int64).
570func (o *Buffer) dec_slice_int64(p *Properties, base uintptr, sbase uintptr) os.Error {
571 u, err := p.valDec(o)
572 if err != nil {
573 return err
574 }
575 x := (*[]int64)(unsafe.Pointer(base + p.offset))
576
577 y := *x
578 c := cap(y)
579 if c == 0 {
580 initSlice(unsafe.Pointer(x), sbase+p.scratch)
581 y = *x
582 c = cap(y)
583 }
584 l := len(y)
585 if l >= c {
586 g := l * 3 / 2
587 z := make([]int64, l, g)
588 copy(z, y)
589 y = z
590 }
591 y = y[0 : l+1]
592 y[l] = int64(u)
593 *x = y
594 return nil
595}
596
597// Decode a slice of strings ([]string).
598func (o *Buffer) dec_slice_string(p *Properties, base uintptr, sbase uintptr) os.Error {
599 s, err := o.DecodeStringBytes()
600 if err != nil {
601 return err
602 }
603 x := (*[]string)(unsafe.Pointer(base + p.offset))
604
605 y := *x
606 c := cap(y)
607 if c == 0 {
608 initSlice(unsafe.Pointer(x), sbase+p.scratch)
609 y = *x
610 c = cap(y)
611 }
612 l := len(y)
613 if l >= c {
614 g := l * 3 / 2
615 z := make([]string, l, g)
616 copy(z, y)
617 y = z
618 }
619 y = y[0 : l+1]
620 y[l] = s
621 *x = y
622 return nil
623}
624
625// Decode a slice of slice of bytes ([][]byte).
626func (o *Buffer) dec_slice_slice_byte(p *Properties, base uintptr, sbase uintptr) os.Error {
627 b, err := o.DecodeRawBytes(true)
628 if err != nil {
629 return err
630 }
631 x := (*[][]byte)(unsafe.Pointer(base + p.offset))
632
633 y := *x
634 c := cap(y)
635 if c == 0 {
636 initSlice(unsafe.Pointer(x), sbase+p.scratch)
637 y = *x
638 c = cap(y)
639 }
640 l := len(y)
641 if l >= c {
642 g := l * 3 / 2
643 z := make([][]byte, l, g)
644 copy(z, y)
645 y = z
646 }
647 y = y[0 : l+1]
648 y[l] = b
649 *x = y
650 return nil
651}
652
653// Decode a group.
654func (o *Buffer) dec_struct_group(p *Properties, base uintptr, sbase uintptr) os.Error {
655 ptr := (**struct{})(unsafe.Pointer(base + p.offset))
656 typ := p.stype.Elem().(*reflect.StructType)
657 structv := unsafe.New(typ)
658 bas := uintptr(structv)
659 *ptr = (*struct{})(structv)
660
661 err := o.unmarshalType(p.stype, true, bas)
662
663 return err
664}
665
666// Decode an embedded message.
667func (o *Buffer) dec_struct_message(p *Properties, base uintptr, sbase uintptr) (err os.Error) {
668 raw, e := o.DecodeRawBytes(false)
669 if e != nil {
670 return e
671 }
672
673 ptr := (**struct{})(unsafe.Pointer(base + p.offset))
674 typ := p.stype.Elem().(*reflect.StructType)
675 structv := unsafe.New(typ)
676 bas := uintptr(structv)
677 *ptr = (*struct{})(structv)
678
679 // If the object can unmarshal itself, let it.
680 iv := unsafe.Unreflect(p.stype, unsafe.Pointer(ptr))
681 if u, ok := iv.(Unmarshaler); ok {
682 return u.Unmarshal(raw)
683 }
684
685 obuf := o.buf
686 oi := o.index
687 o.buf = raw
688 o.index = 0
689
690 err = o.unmarshalType(p.stype, false, bas)
691 o.buf = obuf
692 o.index = oi
693
694 return err
695}
696
697// Decode a slice of embedded messages.
698func (o *Buffer) dec_slice_struct_message(p *Properties, base uintptr, sbase uintptr) os.Error {
699 return o.dec_slice_struct(p, false, base, sbase)
700}
701
702// Decode a slice of embedded groups.
703func (o *Buffer) dec_slice_struct_group(p *Properties, base uintptr, sbase uintptr) os.Error {
704 return o.dec_slice_struct(p, true, base, sbase)
705}
706
707// Decode a slice of structs ([]*struct).
708func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base uintptr, sbase uintptr) os.Error {
709
710 x := (*[]*struct{})(unsafe.Pointer(base + p.offset))
711 y := *x
712 c := cap(y)
713 if c == 0 {
714 initSlice(unsafe.Pointer(x), sbase+p.scratch)
715 y = *x
716 c = cap(y)
717 }
718
719 l := len(y)
720 if l >= c {
721 // Create a new slice with 1.5X the capacity.
722 g := l * 3 / 2
723 z := make([]*struct{}, l, g)
724 copy(z, y)
725 y = z
726 }
727 y = y[0 : l+1]
728 *x = y
729
730 typ := p.stype.Elem().(*reflect.StructType)
731 structv := unsafe.New(typ)
732 bas := uintptr(structv)
733 y[l] = (*struct{})(structv)
734
735 if is_group {
736 err := o.unmarshalType(p.stype, is_group, bas)
737 return err
738 }
739
740 raw, err := o.DecodeRawBytes(true)
741 if err != nil {
742 return err
743 }
744
745 // If the object can unmarshal itself, let it.
746 iv := unsafe.Unreflect(p.stype, unsafe.Pointer(&y[l]))
747 if u, ok := iv.(Unmarshaler); ok {
748 return u.Unmarshal(raw)
749 }
750
751 obuf := o.buf
752 oi := o.index
753 o.buf = raw
754 o.index = 0
755
756 err = o.unmarshalType(p.stype, is_group, bas)
757
758 o.buf = obuf
759 o.index = oi
760
761 return err
762}