mirror of
https://github.com/json-iterator/go.git
synced 2025-03-26 21:12:40 +02:00
fix #228
This commit is contained in:
parent
358cfc3929
commit
ea8c33040f
@ -1,6 +1,9 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import "unsafe"
|
import (
|
||||||
|
"unsafe"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
type numberLazyAny struct {
|
type numberLazyAny struct {
|
||||||
baseAny
|
baseAny
|
||||||
@ -29,7 +32,9 @@ func (any *numberLazyAny) ToInt() int {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadInt()
|
val := iter.ReadInt()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +42,9 @@ func (any *numberLazyAny) ToInt32() int32 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadInt32()
|
val := iter.ReadInt32()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +52,9 @@ func (any *numberLazyAny) ToInt64() int64 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadInt64()
|
val := iter.ReadInt64()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +62,9 @@ func (any *numberLazyAny) ToUint() uint {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadUint()
|
val := iter.ReadUint()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +72,9 @@ func (any *numberLazyAny) ToUint32() uint32 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadUint32()
|
val := iter.ReadUint32()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +82,9 @@ func (any *numberLazyAny) ToUint64() uint64 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadUint64()
|
val := iter.ReadUint64()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +92,9 @@ func (any *numberLazyAny) ToFloat32() float32 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadFloat32()
|
val := iter.ReadFloat32()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +102,9 @@ func (any *numberLazyAny) ToFloat64() float64 {
|
|||||||
iter := any.cfg.BorrowIterator(any.buf)
|
iter := any.cfg.BorrowIterator(any.buf)
|
||||||
defer any.cfg.ReturnIterator(iter)
|
defer any.cfg.ReturnIterator(iter)
|
||||||
val := iter.ReadFloat64()
|
val := iter.ReadFloat64()
|
||||||
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
any.err = iter.Error
|
any.err = iter.Error
|
||||||
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ func Test_read_string_as_any(t *testing.T) {
|
|||||||
|
|
||||||
func Test_wrap_string(t *testing.T) {
|
func Test_wrap_string(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
any := WrapString("123")
|
any := Get([]byte("-32000")).MustBeValid()
|
||||||
should.Equal(123, any.ToInt())
|
should.Equal(-32000, any.ToInt())
|
||||||
|
should.NoError(any.LastError())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user