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

Method encodeNumber

document/json/encoder.go:253–278  ·  view source on GitHub ↗
(vp valueProvider, rv reflect.Value)

Source from the content-addressed store, hash-verified

251}
252
253func (e *Encoder) encodeNumber(vp valueProvider, rv reflect.Value) error {
254 switch rv.Kind() {
255 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
256 vp.GetValue().Long(rv.Int())
257 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
258 vp.GetValue().ULong(rv.Uint())
259 case reflect.Float32:
260 vp.GetValue().Float(float32(rv.Float()))
261 case reflect.Float64:
262 vp.GetValue().Double(rv.Float())
263 default:
264 rvt := rv.Type()
265 switch {
266 case rvt.ConvertibleTo(serde.ReflectTypeOf.BigInt):
267 bi := rv.Convert(serde.ReflectTypeOf.BigInt).Interface().(big.Int)
268 vp.GetValue().BigInteger(&bi)
269 case rvt.ConvertibleTo(serde.ReflectTypeOf.BigFloat):
270 bf := rv.Convert(serde.ReflectTypeOf.BigFloat).Interface().(big.Float)
271 vp.GetValue().BigDecimal(&bf)
272 default:
273 return &document.InvalidMarshalError{Message: fmt.Sprintf("incompatible type: %s", rvt.String())}
274 }
275 }
276
277 return nil
278}
279
280// isValidJSONNumber reports whether s is a valid JSON number literal.
281// From https://golang.org/src/encoding/json/encode.go#L652 isValidNumber

Callers 2

encodeStructMethod · 0.95
encodeScalarMethod · 0.95

Calls 8

ULongMethod · 0.80
GetValueMethod · 0.65
StringMethod · 0.65
LongMethod · 0.45
FloatMethod · 0.45
DoubleMethod · 0.45
BigIntegerMethod · 0.45
BigDecimalMethod · 0.45

Tested by

no test coverage detected