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

Method decodeJSONArray

document/json/decoder.go:236–272  ·  view source on GitHub ↗
(tv []interface{}, rv reflect.Value)

Source from the content-addressed store, hash-verified

234}
235
236func (d *Decoder) decodeJSONArray(tv []interface{}, rv reflect.Value) error {
237 var isArray bool
238
239 switch rv.Kind() {
240 case reflect.Slice:
241 // Make room for the slice elements if needed
242 if rv.IsNil() || rv.Cap() < len(tv) {
243 rv.Set(reflect.MakeSlice(rv.Type(), 0, len(tv)))
244 }
245 case reflect.Array:
246 // Limited to capacity of existing array.
247 isArray = true
248 case reflect.Interface:
249 s := make([]interface{}, len(tv))
250 for i, av := range tv {
251 if err := d.decode(av, reflect.ValueOf(&s[i]).Elem(), serde.Tag{}); err != nil {
252 return err
253 }
254 }
255 rv.Set(reflect.ValueOf(s))
256 return nil
257 default:
258 return &document.UnmarshalTypeError{Value: "list", Type: rv.Type()}
259 }
260
261 // If rv is not a slice, array
262 for i := 0; i < rv.Cap() && i < len(tv); i++ {
263 if !isArray {
264 rv.SetLen(i + 1)
265 }
266 if err := d.decode(tv[i], rv.Index(i), serde.Tag{}); err != nil {
267 return err
268 }
269 }
270
271 return nil
272}
273
274func (d *Decoder) decodeJSONString(tv string, rv reflect.Value) error {
275 switch rv.Kind() {

Callers 1

decodeMethod · 0.95

Calls 3

decodeMethod · 0.95
TypeMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected