2020-08-11 12:04:32 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type numberDecoder struct {
|
|
|
|
*floatDecoder
|
2020-11-23 11:16:31 +03:00
|
|
|
op func(unsafe.Pointer, Number)
|
|
|
|
structName string
|
|
|
|
fieldName string
|
2020-08-11 12:04:32 +03:00
|
|
|
}
|
|
|
|
|
2020-11-23 11:16:31 +03:00
|
|
|
func newNumberDecoder(structName, fieldName string, op func(unsafe.Pointer, Number)) *numberDecoder {
|
2020-08-11 12:04:32 +03:00
|
|
|
return &numberDecoder{
|
2020-11-23 11:16:31 +03:00
|
|
|
floatDecoder: newFloatDecoder(structName, fieldName, nil),
|
2020-08-11 12:04:32 +03:00
|
|
|
op: op,
|
2020-11-23 11:16:31 +03:00
|
|
|
structName: structName,
|
|
|
|
fieldName: fieldName,
|
2020-08-11 12:04:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *numberDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
2020-08-11 12:04:32 +03:00
|
|
|
bytes, err := d.floatDecoder.decodeStreamByte(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-05 16:27:33 +03:00
|
|
|
d.op(p, Number(string(bytes)))
|
|
|
|
s.reset()
|
2020-08-11 12:04:32 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-05 18:54:10 +03:00
|
|
|
func (d *numberDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
2020-08-11 12:04:32 +03:00
|
|
|
bytes, c, err := d.floatDecoder.decodeByte(buf, cursor)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
cursor = c
|
|
|
|
s := *(*string)(unsafe.Pointer(&bytes))
|
|
|
|
d.op(p, Number(s))
|
|
|
|
return cursor, nil
|
|
|
|
}
|