SYS-REQ-113
(data []byte, cb func(idx int, value []byte, vt ValueType, err error), nextMatch *int, path []string)
| 19 | |
| 20 | // SYS-REQ-113 |
| 21 | func eachKeyWildcard(data []byte, cb func(idx int, value []byte, vt ValueType, err error), nextMatch *int, path []string) error { |
| 22 | wildcard := wildcardIndex(path) |
| 23 | if wildcard == -1 { |
| 24 | value, valueType, _, err := Get(data, path...) |
| 25 | if err != nil { |
| 26 | // A missing path has no value to report. Parsing errors for a |
| 27 | // located terminal value, however, follow EachKey's convention |
| 28 | // and are delivered to the callback as well as returned. |
| 29 | if err != KeyPathNotFoundError { |
| 30 | cb(*nextMatch, value, valueType, err) |
| 31 | (*nextMatch)++ |
| 32 | } |
| 33 | return err |
| 34 | } |
| 35 | |
| 36 | cb(*nextMatch, value, valueType, nil) |
| 37 | (*nextMatch)++ |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | array, valueType, _, err := Get(data, path[:wildcard]...) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | if valueType != Array { |
| 46 | return MalformedArrayError |
| 47 | } |
| 48 | |
| 49 | remaining := path[wildcard+1:] |
| 50 | _, err = ArrayEachErr(array, func(value []byte, elementType ValueType, _ int, parseErr error) error { |
| 51 | if parseErr != nil { |
| 52 | cb(*nextMatch, value, elementType, parseErr) |
| 53 | (*nextMatch)++ |
| 54 | return parseErr |
| 55 | } |
| 56 | |
| 57 | if len(remaining) == 0 { |
| 58 | cb(*nextMatch, value, elementType, nil) |
| 59 | (*nextMatch)++ |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | return eachKeyWildcard(value, cb, nextMatch, remaining) |
| 64 | }) |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | // ArrayEachWildcard iterates over an array addressed by keys. A terminal [*] |
| 69 | // component is accepted as an explicit request for all elements; without it, |
no test coverage detected