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

Method decodeJSONNumber

document/json/decoder.go:97–181  ·  view source on GitHub ↗
(tv json.Number, rv reflect.Value)

Source from the content-addressed store, hash-verified

95}
96
97func (d *Decoder) decodeJSONNumber(tv json.Number, rv reflect.Value) error {
98 switch rv.Kind() {
99 case reflect.Interface:
100 rv.Set(reflect.ValueOf(document.Number(tv)))
101 case reflect.String:
102 // covers document.Number
103 rv.SetString(tv.String())
104 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
105 i, err := tv.Int64()
106 if err != nil {
107 return err
108 }
109 if rv.OverflowInt(i) {
110 return &document.UnmarshalTypeError{
111 Value: fmt.Sprintf("number overflow, %s", tv.String()),
112 Type: rv.Type(),
113 }
114 }
115 rv.SetInt(i)
116 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
117 u, err := document.Number(tv).Uint64()
118 if err != nil {
119 return err
120 }
121 if rv.OverflowUint(u) {
122 return &document.UnmarshalTypeError{
123 Value: fmt.Sprintf("number overflow, %s", tv.String()),
124 Type: rv.Type(),
125 }
126 }
127 rv.SetUint(u)
128 case reflect.Float32:
129 f, err := document.Number(tv).Float32()
130 if err != nil {
131 return err
132 }
133 if rv.OverflowFloat(f) {
134 return &document.UnmarshalTypeError{
135 Value: fmt.Sprintf("float overflow, %s", tv.String()),
136 Type: rv.Type(),
137 }
138 }
139 rv.SetFloat(f)
140 case reflect.Float64:
141 f, err := document.Number(tv).Float64()
142 if err != nil {
143 return err
144 }
145 if rv.OverflowFloat(f) {
146 return &document.UnmarshalTypeError{
147 Value: fmt.Sprintf("float overflow, %s", tv.String()),
148 Type: rv.Type(),
149 }
150 }
151 rv.SetFloat(f)
152 default:
153 rvt := rv.Type()
154 switch {

Callers 1

decodeMethod · 0.95

Calls 7

NumberTypeAlias · 0.92
Int64Method · 0.80
Uint64Method · 0.80
Float32Method · 0.80
Float64Method · 0.80
StringMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected