github.com/trim21/go-phpserialize@v0.0.22-0.20240301204449-2fca0319b3f0/internal/decoder/anonymous_field.go (about) 1 package decoder 2 3 import ( 4 "unsafe" 5 6 "github.com/trim21/go-phpserialize/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) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, 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.Decode(ctx, cursor, depth, unsafe.Pointer(uintptr(p)+d.offset)) 29 }