anonymous_field.go (1165B)
1 package decoder 2 3 import ( 4 "unsafe" 5 6 "github.com/goccy/go-json/internal/runtime" 7 ) 8 9 type anonymousFieldDecoder struct { 10 structType *runtime.Type 11 offset uintptr 12 dec Decoder 13 } 14 15 func newAnonymousFieldDecoder(structType *runtime.Type, offset uintptr, dec Decoder) *anonymousFieldDecoder { 16 return &anonymousFieldDecoder{ 17 structType: structType, 18 offset: offset, 19 dec: dec, 20 } 21 } 22 23 func (d *anonymousFieldDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error { 24 if *(*unsafe.Pointer)(p) == nil { 25 *(*unsafe.Pointer)(p) = unsafe_New(d.structType) 26 } 27 p = *(*unsafe.Pointer)(p) 28 return d.dec.DecodeStream(s, depth, unsafe.Pointer(uintptr(p)+d.offset)) 29 } 30 31 func (d *anonymousFieldDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) { 32 if *(*unsafe.Pointer)(p) == nil { 33 *(*unsafe.Pointer)(p) = unsafe_New(d.structType) 34 } 35 p = *(*unsafe.Pointer)(p) 36 return d.dec.Decode(ctx, cursor, depth, unsafe.Pointer(uintptr(p)+d.offset)) 37 } 38 39 func (d *anonymousFieldDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) { 40 return d.dec.DecodePath(ctx, cursor, depth) 41 }