MCPcopy Create free account
hub / github.com/apache/fory / Reserve

Method Reserve

go/fory/buffer.go:517–531  ·  view source on GitHub ↗

Reserve ensures buffer has at least n bytes available for writing from current position. Call this before multiple unsafe writes to avoid repeated grow() calls.

(n int)

Source from the content-addressed store, hash-verified

515// Reserve ensures buffer has at least n bytes available for writing from current position.
516// Call this before multiple unsafe writes to avoid repeated grow() calls.
517func (b *ByteBuffer) Reserve(n int) {
518 needed := b.writerIndex + n
519 if needed <= len(b.data) {
520 return // Already have enough space
521 }
522 // Need to expand - calculate new size
523 if needed <= cap(b.data) {
524 b.data = b.data[:cap(b.data)]
525 } else {
526 newCap := 2 * needed
527 newBuf := make([]byte, newCap, newCap)
528 copy(newBuf, b.data)
529 b.data = newBuf
530 }
531}
532
533// UnsafeWriteVarint32 writes a varint32 without grow check.
534// Caller must have called Reserve(5) beforehand.

Callers 3

writeStringFunction · 0.45
WriteDataMethod · 0.45

Calls

no outgoing calls

Tested by 1