GetBytes will read and fill the slice p as much as possible. If p is not passed, return all readable bytes.
(p [][]byte)
| 668 | // GetBytes will read and fill the slice p as much as possible. |
| 669 | // If p is not passed, return all readable bytes. |
| 670 | func (b *UnsafeLinkBuffer) GetBytes(p [][]byte) (vs [][]byte) { |
| 671 | node, flush := b.read, b.flush |
| 672 | if len(p) == 0 { |
| 673 | n := 0 |
| 674 | for ; node != flush; node = node.next { |
| 675 | n++ |
| 676 | } |
| 677 | node = b.read |
| 678 | p = make([][]byte, n) |
| 679 | } |
| 680 | var i int |
| 681 | for i = 0; node != flush && i < len(p); node = node.next { |
| 682 | if node.Len() > 0 { |
| 683 | node.setFlag(flagReadExposed) |
| 684 | p[i] = node.buf[node.off:] |
| 685 | i++ |
| 686 | } |
| 687 | } |
| 688 | if i < len(p) { |
| 689 | flush.setFlag(flagReadExposed) |
| 690 | p[i] = flush.buf[flush.off:] |
| 691 | i++ |
| 692 | } |
| 693 | return p[:i] |
| 694 | } |
| 695 | |
| 696 | // book will grow and malloc buffer to hold data. |
| 697 | // |