2020-05-08 14:22:57 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type unmarshalJSONDecoder struct {
|
|
|
|
typ *rtype
|
|
|
|
}
|
|
|
|
|
|
|
|
func newUnmarshalJSONDecoder(typ *rtype) *unmarshalJSONDecoder {
|
|
|
|
return &unmarshalJSONDecoder{typ: typ}
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *unmarshalJSONDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
2020-07-30 16:41:53 +03:00
|
|
|
s.skipWhiteSpace()
|
|
|
|
start := s.cursor
|
|
|
|
if err := s.skipValue(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
src := s.buf[start:s.cursor]
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: d.typ,
|
2020-11-14 23:27:15 +03:00
|
|
|
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&p)),
|
2020-07-30 16:41:53 +03:00
|
|
|
}))
|
|
|
|
if err := v.(Unmarshaler).UnmarshalJSON(src); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *unmarshalJSONDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
2020-05-08 14:22:57 +03:00
|
|
|
cursor = skipWhiteSpace(buf, cursor)
|
|
|
|
start := cursor
|
|
|
|
end, err := skipValue(buf, cursor)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
src := buf[start:end]
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: d.typ,
|
2020-11-14 23:27:15 +03:00
|
|
|
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&p)),
|
2020-05-08 14:22:57 +03:00
|
|
|
}))
|
|
|
|
if err := v.(Unmarshaler).UnmarshalJSON(src); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return end, nil
|
|
|
|
}
|