(key string)
| 579 | } |
| 580 | |
| 581 | func (j *jsonEncoded) Exists(key string) (bool, error) { |
| 582 | if dec := j.alreadyDecoded(); dec != nil { |
| 583 | return dec.Exists(key) |
| 584 | } |
| 585 | |
| 586 | switch j.typ { |
| 587 | case ObjectJSONType: |
| 588 | v, err := j.FetchValKey(key) |
| 589 | if err != nil { |
| 590 | return false, err |
| 591 | } |
| 592 | return v != nil, nil |
| 593 | case ArrayJSONType: |
| 594 | iter := j.iterArrayValues() |
| 595 | for { |
| 596 | nextJEntry, data, ok, err := iter.nextEncoded() |
| 597 | if err != nil { |
| 598 | return false, err |
| 599 | } |
| 600 | if !ok { |
| 601 | return false, nil |
| 602 | } |
| 603 | next, err := newEncoded(nextJEntry, data) |
| 604 | if err != nil { |
| 605 | return false, err |
| 606 | } |
| 607 | // This is a minor optimization - we know that newEncoded always returns a |
| 608 | // jsonEncoded if it's decoding a string, and we can save actually |
| 609 | // allocating that string for this check by not forcing a decode into a |
| 610 | // jsonString. This operates on two major assumptions: |
| 611 | // 1. newEncoded returns a jsonEncoded (and not a jsonString) for string |
| 612 | // types and |
| 613 | // 2. the `value` field on such a jsonEncoded directly corresponds to the string. |
| 614 | // This is tested sufficiently that if either of those assumptions is |
| 615 | // broken it will be caught. |
| 616 | if next.Type() == StringJSONType && string(next.(*jsonEncoded).value) == key { |
| 617 | return true, nil |
| 618 | } |
| 619 | } |
| 620 | default: |
| 621 | s, err := j.decode() |
| 622 | if err != nil { |
| 623 | return false, err |
| 624 | } |
| 625 | return s.Exists(key) |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | func (j *jsonEncoded) FetchValKeyOrIdx(key string) (JSON, error) { |
| 630 | switch j.typ { |
nothing calls this directly
no test coverage detected