2017-01-22 23:29:48 +08:00
|
|
|
package jsoniter
|
|
|
|
|
2017-01-22 23:38:55 +08:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2017-01-22 23:29:48 +08:00
|
|
|
type floatLazyAny struct {
|
2017-01-24 00:23:07 +08:00
|
|
|
baseAny
|
2017-01-22 23:29:48 +08:00
|
|
|
buf []byte
|
|
|
|
iter *Iterator
|
|
|
|
err error
|
2017-01-22 23:38:55 +08:00
|
|
|
cache float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) fillCache() {
|
|
|
|
if any.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
iter := any.iter
|
|
|
|
if iter == nil {
|
|
|
|
iter = NewIterator()
|
|
|
|
}
|
|
|
|
iter.ResetBytes(any.buf)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) LastError() error {
|
|
|
|
return any.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToBool() bool {
|
2017-01-22 23:38:55 +08:00
|
|
|
return any.ToFloat64() != 0
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToInt() int {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToInt32() int32 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int32(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToInt64() int64 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return int64(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToFloat32() float32 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return float32(any.cache)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToFloat64() float64 {
|
2017-01-22 23:38:55 +08:00
|
|
|
any.fillCache()
|
|
|
|
return any.cache
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) ToString() string {
|
2017-01-22 23:38:55 +08:00
|
|
|
return *(*string)(unsafe.Pointer(&any.buf))
|
2017-01-26 14:56:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatLazyAny) WriteTo(stream *Stream) {
|
|
|
|
stream.Write(any.buf)
|
2017-01-22 23:29:48 +08:00
|
|
|
}
|