MCPcopy Create free account
hub / github.com/aws/smithy-go / decodeFloat

Method decodeFloat

document/cbor/decode.go:136–170  ·  view source on GitHub ↗
(v float64, rv reflect.Value)

Source from the content-addressed store, hash-verified

134}
135
136func (d *decoder) decodeFloat(v float64, rv reflect.Value) error {
137 switch rv.Kind() {
138 case reflect.Interface:
139 rv.Set(reflect.ValueOf(v))
140 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
141 i, accuracy := big.NewFloat(v).Int64()
142 if accuracy != big.Exact || rv.OverflowInt(i) {
143 return &document.UnmarshalTypeError{
144 Value: fmt.Sprintf("int overflow, %e", v),
145 Type: rv.Type(),
146 }
147 }
148 rv.SetInt(i)
149 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
150 u, accuracy := big.NewFloat(v).Uint64()
151 if accuracy != big.Exact || rv.OverflowUint(u) {
152 return &document.UnmarshalTypeError{
153 Value: fmt.Sprintf("uint overflow, %e", v),
154 Type: rv.Type(),
155 }
156 }
157 rv.SetUint(u)
158 case reflect.Float32, reflect.Float64:
159 if rv.OverflowFloat(v) {
160 return &document.UnmarshalTypeError{
161 Value: fmt.Sprintf("float overflow, %e", v),
162 Type: rv.Type(),
163 }
164 }
165 rv.SetFloat(v)
166 default:
167 return &document.UnmarshalTypeError{Value: "number", Type: rv.Type()}
168 }
169 return nil
170}
171
172func (d *decoder) decodeList(v cbor.List, rv reflect.Value) error {
173 var isArray bool

Callers 1

decodeMethod · 0.95

Calls 3

Int64Method · 0.80
Uint64Method · 0.80
SetMethod · 0.45

Tested by

no test coverage detected