2020-05-08 14:25:49 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type unmarshalTextDecoder struct {
|
|
|
|
typ *rtype
|
|
|
|
}
|
|
|
|
|
|
|
|
func newUnmarshalTextDecoder(typ *rtype) *unmarshalTextDecoder {
|
|
|
|
return &unmarshalTextDecoder{typ: typ}
|
|
|
|
}
|
|
|
|
|
2020-08-11 13:05:20 +03:00
|
|
|
func (d *unmarshalTextDecoder) setDisallowUnknownFields(_ bool) {}
|
|
|
|
|
2020-07-30 16:41:53 +03:00
|
|
|
func (d *unmarshalTextDecoder) decodeStream(s *stream, p uintptr) error {
|
|
|
|
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,
|
|
|
|
ptr: unsafe.Pointer(p),
|
|
|
|
}))
|
|
|
|
if err := v.(encoding.TextUnmarshaler).UnmarshalText(src); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-23 06:51:09 +03:00
|
|
|
func (d *unmarshalTextDecoder) decode(buf []byte, cursor int64, p uintptr) (int64, error) {
|
2020-05-08 14:25:49 +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.(encoding.TextUnmarshaler).UnmarshalText(src); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return end, nil
|
|
|
|
}
|