(key string)
| 616 | } |
| 617 | |
| 618 | func (j *jsonEncoded) Exists(key string) (bool, error) { |
| 619 | if dec := j.alreadyDecoded(); dec != nil { |
| 620 | return dec.Exists(key) |
| 621 | } |
| 622 | |
| 623 | switch j.typ { |
| 624 | case ObjectJSONType: |
| 625 | v, err := j.FetchValKey(key) |
| 626 | if err != nil { |
| 627 | return false, err |
| 628 | } |
| 629 | return v != nil, nil |
| 630 | case ArrayJSONType: |
| 631 | iter := j.iterArrayValues() |
| 632 | for { |
| 633 | nextJEntry, data, ok, err := iter.nextEncoded() |
| 634 | if err != nil { |
| 635 | return false, err |
| 636 | } |
| 637 | if !ok { |
| 638 | return false, nil |
| 639 | } |
| 640 | next, err := newEncoded(nextJEntry, data) |
| 641 | if err != nil { |
| 642 | return false, err |
| 643 | } |
| 644 | // This is a minor optimization - we know that newEncoded always returns a |
| 645 | // jsonEncoded if it's decoding a string, and we can save actually |
| 646 | // allocating that string for this check by not forcing a decode into a |
| 647 | // jsonString. This operates on two major assumptions: |
| 648 | // 1. newEncoded returns a jsonEncoded (and not a jsonString) for string |
| 649 | // types and |
| 650 | // 2. the `value` field on such a jsonEncoded directly corresponds to the string. |
| 651 | // This is tested sufficiently that if either of those assumptions is |
| 652 | // broken it will be caught. |
| 653 | if next.Type() == StringJSONType && string(next.(*jsonEncoded).value) == key { |
| 654 | return true, nil |
| 655 | } |
| 656 | } |
| 657 | default: |
| 658 | s, err := j.decode() |
| 659 | if err != nil { |
| 660 | return false, err |
| 661 | } |
| 662 | return s.Exists(key) |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | func (j *jsonEncoded) FetchValKeyOrIdx(key string) (JSON, error) { |
| 667 | switch j.typ { |
nothing calls this directly
no test coverage detected