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

Method decodeJSONFloat64

document/json/decoder.go:183–234  ·  view source on GitHub ↗
(tv float64, rv reflect.Value)

Source from the content-addressed store, hash-verified

181}
182
183func (d *Decoder) decodeJSONFloat64(tv float64, rv reflect.Value) error {
184 switch rv.Kind() {
185 case reflect.Interface:
186 rv.Set(reflect.ValueOf(tv))
187 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
188 i, accuracy := big.NewFloat(tv).Int64()
189 if accuracy != big.Exact || rv.OverflowInt(i) {
190 return &document.UnmarshalTypeError{
191 Value: fmt.Sprintf("number overflow, %e", tv),
192 Type: rv.Type(),
193 }
194 }
195 rv.SetInt(i)
196 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
197 u, accuracy := big.NewFloat(tv).Uint64()
198 if accuracy != big.Exact || rv.OverflowUint(u) {
199 return &document.UnmarshalTypeError{
200 Value: fmt.Sprintf("number overflow, %e", tv),
201 Type: rv.Type(),
202 }
203 }
204 rv.SetUint(u)
205 case reflect.Float32, reflect.Float64:
206 if rv.OverflowFloat(tv) {
207 return &document.UnmarshalTypeError{
208 Value: fmt.Sprintf("float overflow, %e", tv),
209 Type: rv.Type(),
210 }
211 }
212 rv.SetFloat(tv)
213 default:
214 rvt := rv.Type()
215 switch {
216 case rvt.ConvertibleTo(serde.ReflectTypeOf.BigFloat):
217 f := big.NewFloat(tv)
218 rv.Set(reflect.ValueOf(*f).Convert(rvt))
219 case rvt.ConvertibleTo(serde.ReflectTypeOf.BigInt):
220 i, accuracy := big.NewFloat(tv).Int(nil)
221 if accuracy != big.Exact {
222 return &document.UnmarshalTypeError{
223 Value: fmt.Sprintf("int overflow, %e", tv),
224 Type: rv.Type(),
225 }
226 }
227 rv.Set(reflect.ValueOf(*i).Convert(rvt))
228 default:
229 return &document.UnmarshalTypeError{Value: "number", Type: rv.Type()}
230 }
231 }
232
233 return nil
234}
235
236func (d *Decoder) decodeJSONArray(tv []interface{}, rv reflect.Value) error {
237 var isArray bool

Callers 1

decodeMethod · 0.95

Calls 4

Int64Method · 0.80
TypeMethod · 0.80
Uint64Method · 0.80
SetMethod · 0.45

Tested by

no test coverage detected