MCPcopy Create free account
hub / github.com/cockroachdb/redact / startRedactable

Method startRedactable

internal/buffer/buffer.go:222–244  ·  view source on GitHub ↗

startRedactable adds the opening redaction marker.

()

Source from the content-addressed store, hash-verified

220
221// startRedactable adds the opening redaction marker.
222func (b *Buffer) startRedactable() {
223 if bytes.HasSuffix(b.buf, m.EndBytes) {
224 // Optimization: merge adjacent unsafe zones by removing the
225 // trailing › instead of writing a new ‹. However, we must NOT
226 // merge into a hash zone (‹†...›), because that would cause the
227 // next value to be hashed together with the hash-marked value.
228 preceding := b.buf[:len(b.buf)-m.EndLen]
229 startIdx := bytes.LastIndex(preceding, m.StartBytes)
230 isHashZone := startIdx >= 0 &&
231 bytes.HasPrefix(preceding[startIdx+m.StartLen:], m.HashPrefixBytes)
232 if !isHashZone {
233 b.buf = preceding
234 b.markerOpen = true
235 return
236 }
237 }
238 p, ok := b.tryGrowByReslice(len(m.StartS))
239 if !ok {
240 p = b.grow(len(m.StartS))
241 }
242 copy(b.buf[p:], m.StartS)
243 b.markerOpen = true
244}
245
246// escapeToEnd escapes occurrences of redaction markers in
247// b.buf[b.validUntil:] and advances b.validUntil until the end.

Callers 1

startWriteMethod · 0.95

Calls 2

tryGrowByResliceMethod · 0.95
growMethod · 0.95

Tested by

no test coverage detected