------------------------------------------ implement connection interface ------------------------------------------ Bytes returns all the readable bytes of this LinkBuffer.
()
| 650 | |
| 651 | // Bytes returns all the readable bytes of this LinkBuffer. |
| 652 | func (b *UnsafeLinkBuffer) Bytes() []byte { |
| 653 | node, flush := b.read, b.flush |
| 654 | if node == flush { |
| 655 | return node.buf[node.off:] |
| 656 | } |
| 657 | n := 0 |
| 658 | p := dirtmake.Bytes(b.Len(), b.Len()) |
| 659 | for ; node != flush; node = node.next { |
| 660 | if node.Len() > 0 { |
| 661 | n += copy(p[n:], node.buf[node.off:]) |
| 662 | } |
| 663 | } |
| 664 | n += copy(p[n:], flush.buf[flush.off:]) |
| 665 | return p[:n] |
| 666 | } |
| 667 | |
| 668 | // GetBytes will read and fill the slice p as much as possible. |
| 669 | // If p is not passed, return all readable bytes. |