blob: 9d1e901a66ad36f15646eebbdfde5f80fae5a6b8 [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001package jsoniter
2
3import (
4 "io"
5 "unsafe"
6)
7
8type numberLazyAny struct {
9 baseAny
10 cfg *frozenConfig
11 buf []byte
12 err error
13}
14
15func (any *numberLazyAny) ValueType() ValueType {
16 return NumberValue
17}
18
19func (any *numberLazyAny) MustBeValid() Any {
20 return any
21}
22
23func (any *numberLazyAny) LastError() error {
24 return any.err
25}
26
27func (any *numberLazyAny) ToBool() bool {
28 return any.ToFloat64() != 0
29}
30
31func (any *numberLazyAny) ToInt() int {
32 iter := any.cfg.BorrowIterator(any.buf)
33 defer any.cfg.ReturnIterator(iter)
34 val := iter.ReadInt()
35 if iter.Error != nil && iter.Error != io.EOF {
36 any.err = iter.Error
37 }
38 return val
39}
40
41func (any *numberLazyAny) ToInt32() int32 {
42 iter := any.cfg.BorrowIterator(any.buf)
43 defer any.cfg.ReturnIterator(iter)
44 val := iter.ReadInt32()
45 if iter.Error != nil && iter.Error != io.EOF {
46 any.err = iter.Error
47 }
48 return val
49}
50
51func (any *numberLazyAny) ToInt64() int64 {
52 iter := any.cfg.BorrowIterator(any.buf)
53 defer any.cfg.ReturnIterator(iter)
54 val := iter.ReadInt64()
55 if iter.Error != nil && iter.Error != io.EOF {
56 any.err = iter.Error
57 }
58 return val
59}
60
61func (any *numberLazyAny) ToUint() uint {
62 iter := any.cfg.BorrowIterator(any.buf)
63 defer any.cfg.ReturnIterator(iter)
64 val := iter.ReadUint()
65 if iter.Error != nil && iter.Error != io.EOF {
66 any.err = iter.Error
67 }
68 return val
69}
70
71func (any *numberLazyAny) ToUint32() uint32 {
72 iter := any.cfg.BorrowIterator(any.buf)
73 defer any.cfg.ReturnIterator(iter)
74 val := iter.ReadUint32()
75 if iter.Error != nil && iter.Error != io.EOF {
76 any.err = iter.Error
77 }
78 return val
79}
80
81func (any *numberLazyAny) ToUint64() uint64 {
82 iter := any.cfg.BorrowIterator(any.buf)
83 defer any.cfg.ReturnIterator(iter)
84 val := iter.ReadUint64()
85 if iter.Error != nil && iter.Error != io.EOF {
86 any.err = iter.Error
87 }
88 return val
89}
90
91func (any *numberLazyAny) ToFloat32() float32 {
92 iter := any.cfg.BorrowIterator(any.buf)
93 defer any.cfg.ReturnIterator(iter)
94 val := iter.ReadFloat32()
95 if iter.Error != nil && iter.Error != io.EOF {
96 any.err = iter.Error
97 }
98 return val
99}
100
101func (any *numberLazyAny) ToFloat64() float64 {
102 iter := any.cfg.BorrowIterator(any.buf)
103 defer any.cfg.ReturnIterator(iter)
104 val := iter.ReadFloat64()
105 if iter.Error != nil && iter.Error != io.EOF {
106 any.err = iter.Error
107 }
108 return val
109}
110
111func (any *numberLazyAny) ToString() string {
112 return *(*string)(unsafe.Pointer(&any.buf))
113}
114
115func (any *numberLazyAny) WriteTo(stream *Stream) {
116 stream.Write(any.buf)
117}
118
119func (any *numberLazyAny) GetInterface() interface{} {
120 iter := any.cfg.BorrowIterator(any.buf)
121 defer any.cfg.ReturnIterator(iter)
122 return iter.Read()
123}