MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / unmarshal

Method unmarshal

opensca/sca/java/xml/read.go:320–633  ·  view source on GitHub ↗

Unmarshal a single XML element into val.

(val reflect.Value, start *StartElement, depth int)

Source from the content-addressed store, hash-verified

318
319// Unmarshal a single XML element into val.
320func (d *Decoder) unmarshal(val reflect.Value, start *StartElement, depth int) error {
321 if depth >= maxUnmarshalDepth || runtime.GOARCH == "wasm" && depth >= maxUnmarshalDepthWasm {
322 return errUnmarshalDepth
323 }
324 // Find start element if we need it.
325 if start == nil {
326 for {
327 tok, err := d.Token()
328 if err != nil {
329 return err
330 }
331 if t, ok := tok.(StartElement); ok {
332 start = &t
333 break
334 }
335 }
336 }
337
338 // Load value from interface, but only if the result will be
339 // usefully addressable.
340 if val.Kind() == reflect.Interface && !val.IsNil() {
341 e := val.Elem()
342 if e.Kind() == reflect.Pointer && !e.IsNil() {
343 val = e
344 }
345 }
346
347 if val.Kind() == reflect.Pointer {
348 if val.IsNil() {
349 val.Set(reflect.New(val.Type().Elem()))
350 }
351 val = val.Elem()
352 }
353
354 if val.CanInterface() && val.Type().Implements(unmarshalerType) {
355 // This is an unmarshaler with a non-pointer receiver,
356 // so it's likely to be incorrect, but we do what we're told.
357 return d.unmarshalInterface(val.Interface().(Unmarshaler), start)
358 }
359
360 if val.CanAddr() {
361 pv := val.Addr()
362 if pv.CanInterface() && pv.Type().Implements(unmarshalerType) {
363 return d.unmarshalInterface(pv.Interface().(Unmarshaler), start)
364 }
365 }
366
367 if val.CanInterface() && val.Type().Implements(textUnmarshalerType) {
368 return d.unmarshalTextInterface(val.Interface().(encoding.TextUnmarshaler))
369 }
370
371 if val.CanAddr() {
372 pv := val.Addr()
373 if pv.CanInterface() && pv.Type().Implements(textUnmarshalerType) {
374 return d.unmarshalTextInterface(pv.Interface().(encoding.TextUnmarshaler))
375 }
376 }
377

Callers 2

DecodeElementMethod · 0.95
unmarshalPathMethod · 0.95

Calls 13

TokenMethod · 0.95
unmarshalInterfaceMethod · 0.95
SkipMethod · 0.95
unmarshalAttrMethod · 0.95
savedOffsetMethod · 0.95
unmarshalPathMethod · 0.95
getTypeInfoFunction · 0.85
UnmarshalErrorTypeAlias · 0.85
copyValueFunction · 0.85
IndexMethod · 0.80
valueMethod · 0.80

Tested by

no test coverage detected