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

Method readBinary

nocopy_linkbuffer.go:321–346  ·  view source on GitHub ↗

readBinary cannot use mcache, because the memory allocated by readBinary will not be recycled.

(n int)

Source from the content-addressed store, hash-verified

319
320// readBinary cannot use mcache, because the memory allocated by readBinary will not be recycled.
321func (b *UnsafeLinkBuffer) readBinary(n int) (p []byte) {
322 b.recalLen(-n) // re-cal length
323
324 // single node
325 if b.isSingleNode(n) {
326 p = dirtmake.Bytes(n, n)
327 copy(p, b.read.Next(n))
328 return p
329 }
330 p = dirtmake.Bytes(n, n)
331 // multiple nodes
332 var pIdx int
333 var l int
334 for ack := n; ack > 0; ack = ack - l {
335 l = b.read.Len()
336 if l >= ack {
337 pIdx += copy(p[pIdx:], b.read.Next(ack))
338 break
339 } else if l > 0 {
340 pIdx += copy(p[pIdx:], b.read.Next(l))
341 }
342 b.read = b.read.next
343 }
344 _ = pIdx
345 return p
346}
347
348// ReadByte implements Reader.
349func (b *UnsafeLinkBuffer) ReadByte() (p byte, err error) {

Callers 2

ReadStringMethod · 0.95
ReadBinaryMethod · 0.95

Calls 5

recalLenMethod · 0.95
isSingleNodeMethod · 0.95
NextMethod · 0.65
LenMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected