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

Function prettyPrintInvertedIndexKey

pkg/util/encoding/encoding.go:867–913  ·  view source on GitHub ↗

prettyPrintInvertedIndexKey returns a string representation of the path part of a JSON inverted index.

(b []byte)

Source from the content-addressed store, hash-verified

865// prettyPrintInvertedIndexKey returns a string representation of the path part of a JSON inverted
866// index.
867func prettyPrintInvertedIndexKey(b []byte) (string, []byte, error) {
868 outBytes := ""
869 // We're skipping the first byte because it's the JSON tag.
870 tempB := b[1:]
871 for {
872 i := bytes.IndexByte(tempB, escape)
873
874 if i == -1 {
875 return "", nil, errors.Errorf("did not find terminator %#x in buffer %#x", escape, b)
876 }
877 if i+1 >= len(tempB) {
878 return "", nil, errors.Errorf("malformed escape in buffer %#x", b)
879 }
880
881 switch tempB[i+1] {
882 case escapedTerm:
883 if len(tempB[:i]) > 0 {
884 outBytes = outBytes + strconv.Quote(UnsafeConvertBytesToString(tempB[:i]))
885 } else {
886 lenOut := len(outBytes)
887 if lenOut > 1 && outBytes[lenOut-1] == '/' {
888 outBytes = outBytes[:lenOut-1]
889 }
890 }
891 return outBytes, tempB[i+escapeLength:], nil
892 case escapedJSONObjectKeyTerm:
893 outBytes = outBytes + strconv.Quote(UnsafeConvertBytesToString(tempB[:i])) + "/"
894 case escapedJSONArray:
895 outBytes = outBytes + "Arr/"
896 if i+2 >= len(tempB) {
897 // The key ends in an escaped JSON array byte, which is used in
898 // spans to scan over non-empty arrays.
899 return outBytes, nil, nil
900 }
901 case escaped00:
902 if i+2 >= len(tempB) {
903 // The key ends in an escaped NULL byte.
904 return outBytes, nil, nil
905 }
906 default:
907 return "", nil, errors.Errorf("malformed escape in buffer %#x", b)
908
909 }
910
911 tempB = tempB[i+escapeLength:]
912 }
913}
914
915// UnsafeConvertStringToBytes converts a string to a byte array to be used with
916// string encoding functions. Note that the output byte array should not be

Callers 1

prettyPrintFirstValueFunction · 0.85

Calls 2

ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…