decodeBytesInternal decodes an encoded []byte value from b and appends it to r. The remainder of b and the decoded []byte are returned. If deepCopy is true, then the decoded []byte will be deep copied from b and there will no aliasing of the same memory.
( b []byte, r []byte, e escapes, expectMarker bool, deepCopy bool, )
| 775 | // true, then the decoded []byte will be deep copied from b and there will no |
| 776 | // aliasing of the same memory. |
| 777 | func decodeBytesInternal( |
| 778 | b []byte, r []byte, e escapes, expectMarker bool, deepCopy bool, |
| 779 | ) ([]byte, []byte, error) { |
| 780 | if expectMarker { |
| 781 | if len(b) == 0 || b[0] != e.marker { |
| 782 | return nil, nil, errors.Errorf("did not find marker %#x in buffer %#x", e.marker, b) |
| 783 | } |
| 784 | b = b[1:] |
| 785 | } |
| 786 | |
| 787 | for { |
| 788 | i := bytes.IndexByte(b, e.escape) |
| 789 | if i == -1 { |
| 790 | return nil, nil, errors.Errorf("did not find terminator %#x in buffer %#x", e.escape, b) |
| 791 | } |
| 792 | if i+1 >= len(b) { |
| 793 | return nil, nil, errors.Errorf("malformed escape in buffer %#x", b) |
| 794 | } |
| 795 | v := b[i+1] |
| 796 | if v == e.escapedTerm { |
| 797 | if r == nil && !deepCopy { |
| 798 | r = b[:i] |
| 799 | } else { |
| 800 | r = append(r, b[:i]...) |
| 801 | } |
| 802 | return b[i+2:], r, nil |
| 803 | } |
| 804 | |
| 805 | if v != e.escaped00 { |
| 806 | return nil, nil, errors.Errorf("unknown escape sequence: %#x %#x", e.escape, v) |
| 807 | } |
| 808 | |
| 809 | r = append(r, b[:i]...) |
| 810 | r = append(r, e.escapedFF) |
| 811 | b = b[i+2:] |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | // validateDecodeBytesInternal decodes an encoded []byte value from b, |
| 816 | // discarding the decoded value. The remainder of b is returned on success, or a |
no test coverage detected
searching dependent graphs…