2017-01-22 23:29:48 +08:00
|
|
|
package jsoniter
|
|
|
|
|
2017-01-22 23:38:55 +08:00
|
|
|
import (
|
|
|
|
"io"
|
2017-01-26 16:33:16 +08:00
|
|
|
"strconv"
|
2017-06-06 23:27:00 +08:00
|
|
|
"unsafe"
|
2017-01-22 23:38:55 +08:00
|
|
|
)
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
type float64LazyAny struct {
|
2017-01-24 00:23:07 +08:00
|
|
|
baseAny
|
2017-06-06 23:27:00 +08:00
|
|
|
buf []byte
|
|
|
|
iter *Iterator
|
|
|
|
err error
|
2017-01-22 23:38:55 +08:00
|
|
|
cache float64
|
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) Parse() *Iterator {
|
2017-01-22 23:38:55 +08:00
|
|
|
iter := any.iter
|
|
|
|
if iter == nil {
|
2017-06-13 16:58:53 +08:00
|
|
|
iter = NewIterator(DEFAULT_CONFIG)
|
2017-01-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
iter.ResetBytes(any.buf)
|
2017-01-26 15:40:38 +08:00
|
|
|
return iter
|
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ValueType() ValueType {
|
2017-01-26 16:24:01 +08:00
|
|
|
return Number
|
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) fillCache() {
|
2017-01-26 15:40:38 +08:00
|
|
|
if any.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
iter := any.Parse()
|
2017-01-22 23:38:55 +08:00
|
|
|
any.cache = iter.ReadFloat64()
|
|
|
|
if iter.Error != io.EOF {
|
|
|
|
iter.reportError("floatLazyAny", "there are bytes left")
|
|
|
|
}
|
|
|
|
any.err = iter.Error
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) LastError() error {
|
2017-01-22 23:29:48 +08:00
|
|
|
return any.err
|
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToBool() bool {
|
2017-01-22 23:38:55 +08:00
|
|
|
return any.ToFloat64() != 0
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToInt() int {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToInt32() int32 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int32(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToInt64() int64 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int64(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToUint() uint {
|
|
|
|
any.fillCache()
|
|
|
|
return uint(any.cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *float64LazyAny) ToUint32() uint32 {
|
|
|
|
any.fillCache()
|
|
|
|
return uint32(any.cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *float64LazyAny) ToUint64() uint64 {
|
|
|
|
any.fillCache()
|
|
|
|
return uint64(any.cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *float64LazyAny) ToFloat32() float32 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return float32(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToFloat64() float64 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return any.cache
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) ToString() string {
|
2017-01-22 23:38:55 +08:00
|
|
|
return *(*string)(unsafe.Pointer(&any.buf))
|
2017-01-26 14:56:31 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) WriteTo(stream *Stream) {
|
2017-01-26 14:56:31 +08:00
|
|
|
stream.Write(any.buf)
|
2017-01-26 15:44:10 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *float64LazyAny) GetInterface() interface{} {
|
2017-01-26 15:44:10 +08:00
|
|
|
any.fillCache()
|
|
|
|
return any.cache
|
2017-01-26 16:33:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type floatAny struct {
|
|
|
|
baseAny
|
|
|
|
val float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) Parse() *Iterator {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ValueType() ValueType {
|
|
|
|
return Number
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) LastError() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToBool() bool {
|
|
|
|
return any.ToFloat64() != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToInt() int {
|
|
|
|
return int(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToInt32() int32 {
|
|
|
|
return int32(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToInt64() int64 {
|
|
|
|
return int64(any.val)
|
|
|
|
}
|
|
|
|
|
2017-01-29 16:55:32 +08:00
|
|
|
func (any *floatAny) ToUint() uint {
|
|
|
|
return uint(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToUint32() uint32 {
|
|
|
|
return uint32(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToUint64() uint64 {
|
|
|
|
return uint64(any.val)
|
|
|
|
}
|
|
|
|
|
2017-01-26 16:33:16 +08:00
|
|
|
func (any *floatAny) ToFloat32() float32 {
|
|
|
|
return float32(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToFloat64() float64 {
|
|
|
|
return any.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToString() string {
|
|
|
|
return strconv.FormatFloat(any.val, 'E', -1, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) WriteTo(stream *Stream) {
|
|
|
|
stream.WriteFloat64(any.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) GetInterface() interface{} {
|
|
|
|
return any.val
|
2017-06-06 23:27:00 +08:00
|
|
|
}
|