go-json/internal/decoder/anonymous_field.go

42 lines
1.1 KiB
Go
Raw Permalink Normal View History

2021-06-03 12:49:01 +03:00
package decoder
2020-12-22 15:55:59 +03:00
import (
"unsafe"
2021-06-03 12:49:01 +03:00
"github.com/goccy/go-json/internal/runtime"
2020-12-22 15:55:59 +03:00
)
type anonymousFieldDecoder struct {
2021-06-03 12:49:01 +03:00
structType *runtime.Type
2020-12-22 15:55:59 +03:00
offset uintptr
2021-06-03 13:10:17 +03:00
dec Decoder
2020-12-22 15:55:59 +03:00
}
2021-06-03 13:10:17 +03:00
func newAnonymousFieldDecoder(structType *runtime.Type, offset uintptr, dec Decoder) *anonymousFieldDecoder {
2020-12-22 15:55:59 +03:00
return &anonymousFieldDecoder{
structType: structType,
offset: offset,
dec: dec,
}
}
2021-06-03 12:49:01 +03:00
func (d *anonymousFieldDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error {
2020-12-22 15:55:59 +03:00
if *(*unsafe.Pointer)(p) == nil {
*(*unsafe.Pointer)(p) = unsafe_New(d.structType)
}
p = *(*unsafe.Pointer)(p)
2021-06-03 12:49:01 +03:00
return d.dec.DecodeStream(s, depth, unsafe.Pointer(uintptr(p)+d.offset))
2020-12-22 15:55:59 +03:00
}
2021-06-04 19:08:27 +03:00
func (d *anonymousFieldDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) {
2020-12-22 15:55:59 +03:00
if *(*unsafe.Pointer)(p) == nil {
*(*unsafe.Pointer)(p) = unsafe_New(d.structType)
}
p = *(*unsafe.Pointer)(p)
2021-06-04 19:08:27 +03:00
return d.dec.Decode(ctx, cursor, depth, unsafe.Pointer(uintptr(p)+d.offset))
2020-12-22 15:55:59 +03:00
}
2022-11-28 21:55:56 +03:00
func (d *anonymousFieldDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) {
return d.dec.DecodePath(ctx, cursor, depth)
}