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

Method encodeNumber

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

Source from the content-addressed store, hash-verified

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

Callers 2

encodeStructMethod · 0.95
encodeScalarMethod · 0.95

Calls 9

ULongMethod · 0.80
TypeMethod · 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