MCPcopy Create free account
hub / github.com/cloudwego/netpoll / WriteBinary

Method WriteBinary

nocopy_linkbuffer.go:550–569  ·  view source on GitHub ↗

WriteBinary implements Writer.

(p []byte)

Source from the content-addressed store, hash-verified

548
549// WriteBinary implements Writer.
550func (b *UnsafeLinkBuffer) WriteBinary(p []byte) (n int, err error) {
551 n = len(p)
552 if n == 0 {
553 return
554 }
555 b.mallocSize += n
556
557 // TODO: Verify that all nocopy is possible under mcache.
558 if n > BinaryInplaceThreshold {
559 // expand buffer directly with nocopy
560 b.write.next = newLinkBufferNode(0)
561 b.write = b.write.next
562 b.write.buf, b.write.malloc = p[:0], n
563 return n, nil
564 }
565 // here will copy
566 b.growth(n)
567 buf := b.write.Malloc(n)
568 return copy(buf, p), nil
569}
570
571// WriteDirect cannot be mixed with WriteString or WriteBinary functions.
572func (b *UnsafeLinkBuffer) WriteDirect(extra []byte, remainLen int) error {

Callers 1

WriteStringMethod · 0.95

Calls 3

growthMethod · 0.95
newLinkBufferNodeFunction · 0.85
MallocMethod · 0.65

Tested by

no test coverage detected