github.com/night-codes/go-json@v0.9.15/internal/decoder/anonymous_field.go (about) 1 package decoder 2 3 import ( 4 "unsafe" 5 6 "github.com/night-codes/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 }