WriteBinary implements Writer.
(p []byte)
| 548 | |
| 549 | // WriteBinary implements Writer. |
| 550 | func (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. |
| 572 | func (b *UnsafeLinkBuffer) WriteDirect(extra []byte, remainLen int) error { |
no test coverage detected