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

Method decodeList

document/cbor/decode.go:172–208  ·  view source on GitHub ↗
(v cbor.List, rv reflect.Value)

Source from the content-addressed store, hash-verified

170}
171
172func (d *decoder) decodeList(v cbor.List, rv reflect.Value) error {
173 var isArray bool
174
175 switch rv.Kind() {
176 case reflect.Slice:
177 // Make room for the slice elements if needed
178 if rv.IsNil() || rv.Cap() < len(v) {
179 rv.Set(reflect.MakeSlice(rv.Type(), 0, len(v)))
180 }
181 case reflect.Array:
182 // Limited to capacity of existing array.
183 isArray = true
184 case reflect.Interface:
185 s := make([]interface{}, len(v))
186 for i, av := range v {
187 if err := d.decode(av, reflect.ValueOf(&s[i]).Elem(), serde.Tag{}); err != nil {
188 return err
189 }
190 }
191 rv.Set(reflect.ValueOf(s))
192 return nil
193 default:
194 return &document.UnmarshalTypeError{Value: "list", Type: rv.Type()}
195 }
196
197 // If rv is not a slice, array
198 for i := 0; i < rv.Cap() && i < len(v); i++ {
199 if !isArray {
200 rv.SetLen(i + 1)
201 }
202 if err := d.decode(v[i], rv.Index(i), serde.Tag{}); err != nil {
203 return err
204 }
205 }
206
207 return nil
208}
209
210func (d *decoder) decodeString(v string, rv reflect.Value) error {
211 switch rv.Kind() {

Callers 1

decodeMethod · 0.95

Calls 2

decodeMethod · 0.95
SetMethod · 0.45

Tested by

no test coverage detected