(idx int)
| 379 | } |
| 380 | |
| 381 | func (j *jsonEncoded) FetchValIdx(idx int) (JSON, error) { |
| 382 | if dec := j.alreadyDecoded(); dec != nil { |
| 383 | return dec.FetchValIdx(idx) |
| 384 | } |
| 385 | |
| 386 | switch j.typ { |
| 387 | case NumberJSONType, StringJSONType, TrueJSONType, FalseJSONType, NullJSONType: |
| 388 | return fetchValIdxForScalar(j, idx), nil |
| 389 | case ArrayJSONType: |
| 390 | if idx < 0 { |
| 391 | idx = j.containerLen + idx |
| 392 | } |
| 393 | if idx < 0 || idx >= j.containerLen { |
| 394 | return nil, nil |
| 395 | } |
| 396 | |
| 397 | // We need to find the bounds for a given index, but this is nontrivial, |
| 398 | // since some headers store an offset and some store a length. |
| 399 | |
| 400 | begin, end, entry, err := j.getNthEntryBounds(idx) |
| 401 | if err != nil { |
| 402 | return nil, err |
| 403 | } |
| 404 | |
| 405 | return newEncoded(entry, j.arrayGetDataRange(begin, end)) |
| 406 | case ObjectJSONType: |
| 407 | return nil, nil |
| 408 | default: |
| 409 | return nil, errors.AssertionFailedf("unknown json type: %v", errors.Safe(j.typ)) |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | func (j *jsonEncoded) FetchValKey(key string) (JSON, error) { |
| 414 | if dec := j.alreadyDecoded(); dec != nil { |
no test coverage detected