MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / decodeBytesInternal

Function decodeBytesInternal

pkg/util/encoding/encoding.go:777–813  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

775// true, then the decoded []byte will be deep copied from b and there will no
776// aliasing of the same memory.
777func 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

Callers 5

DecodeBytesAscendingFunction · 0.85
DecodeBytesDescendingFunction · 0.85
DecodeGeoAscendingFunction · 0.85
DecodeGeoDescendingFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…