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

Function PrettyPrintValuesWithTypes

pkg/util/encoding/encoding.go:2134–2160  ·  view source on GitHub ↗

PrettyPrintValuesWithTypes returns a slice containing each contiguous decodable value in the provided byte slice along with a slice containing the type of each value. The directions each value is encoded may be provided. If valDirs is nil, all values are decoded and printed with the default directio

(valDirs []Direction, b []byte)

Source from the content-addressed store, hash-verified

2132// The directions each value is encoded may be provided. If valDirs is nil,
2133// all values are decoded and printed with the default direction (ascending).
2134func PrettyPrintValuesWithTypes(valDirs []Direction, b []byte) (vals []string, types []Type) {
2135 vals1, types1, allDecoded := prettyPrintValuesWithTypesImpl(valDirs, b)
2136 if allDecoded {
2137 return vals1, types1
2138 }
2139 // If we failed to decoded everything above, assume the key was the result of a
2140 // `PrefixEnd()`. Attempt to undo PrefixEnd & retry the process, otherwise return
2141 // what we were able to decode.
2142 if undoPrefixEnd, ok := UndoPrefixEnd(b); ok {
2143 // When we UndoPrefixEnd, we may have lost a tail of 0xFFs. Try to add
2144 // enough of them to get something decoded. This is best-effort, we have to stop
2145 // somewhere.
2146 cap := 20
2147 if len(valDirs) > len(b) {
2148 cap = len(valDirs) - len(b)
2149 }
2150 for i := 0; i < cap; i++ {
2151 if vals2, types2, allDecoded := prettyPrintValuesWithTypesImpl(valDirs, undoPrefixEnd); allDecoded {
2152 vals2 = append(vals2, "PrefixEnd")
2153 types2 = append(types2, Bytes)
2154 return vals2, types2
2155 }
2156 undoPrefixEnd = append(undoPrefixEnd, 0xFF)
2157 }
2158 }
2159 return vals1, types1
2160}
2161
2162func prettyPrintValuesWithTypesImpl(
2163 valDirs []Direction, b []byte,

Callers 1

formatSpanFunction · 0.92

Calls 2

UndoPrefixEndFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…