go-json/decode_unmarshal_json.go

32 lines
634 B
Go
Raw Normal View History

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-05-23 06:51:09 +03:00
func (d *unmarshalJSONDecoder) decode(buf []byte, cursor int64, p uintptr) (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,
ptr: unsafe.Pointer(p),
}))
if err := v.(Unmarshaler).UnmarshalJSON(src); err != nil {
return 0, err
}
return end, nil
}