2020-08-11 12:04:32 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type numberDecoder struct {
|
|
|
|
*floatDecoder
|
2020-11-19 06:47:42 +03:00
|
|
|
op func(unsafe.Pointer, Number)
|
2020-08-11 12:04:32 +03:00
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func newNumberDecoder(op func(unsafe.Pointer, Number)) *numberDecoder {
|
2020-08-11 12:04:32 +03:00
|
|
|
return &numberDecoder{
|
|
|
|
floatDecoder: newFloatDecoder(nil),
|
|
|
|
op: op,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
str := *(*string)(unsafe.Pointer(&bytes))
|
|
|
|
d.op(p, Number(str))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *numberDecoder) decode(buf []byte, 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
|
|
|
|
}
|