| 1 |
package decoder |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"unsafe" |
| 6 |
) |
| 7 |
|
| 8 |
type anonymousFieldDecoder struct { |
| 9 |
structType reflect.Type |
| 10 |
offset uintptr |
| 11 |
dec Decoder |
| 12 |
} |
| 13 |
|
| 14 |
func newAnonymousFieldDecoder(structType reflect.Type, offset uintptr, dec Decoder) *anonymousFieldDecoder { |
| 15 |
return &anonymousFieldDecoder{ |
| 16 |
structType: structType, |
| 17 |
offset: offset, |
| 18 |
dec: dec, |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func (d *anonymousFieldDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) { |
| 23 |
if *(*unsafe.Pointer)(p) == nil { |
| 24 |
*(*unsafe.Pointer)(p) = newValue(d.structType) |
| 25 |
} |
| 26 |
p = *(*unsafe.Pointer)(p) |
| 27 |
return d.dec.Decode(ctx, cursor, depth, unsafe.Add(p, d.offset)) |
| 28 |
} |
| 29 |
|
| 30 |
func (d *anonymousFieldDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) { |
| 31 |
return d.dec.DecodePath(ctx, cursor, depth) |
| 32 |
} |