Bytes returns a copy of the current buffer contents in order.
()
| 50 | |
| 51 | // Bytes returns a copy of the current buffer contents in order. |
| 52 | func (t *TruncBuffer) Bytes() []byte { |
| 53 | t.mu.RLock() |
| 54 | defer t.mu.RUnlock() |
| 55 | |
| 56 | if !t.full { |
| 57 | return append([]byte(nil), t.buf[:t.head]...) |
| 58 | } |
| 59 | |
| 60 | out := make([]byte, t.size) |
| 61 | n := copy(out, t.buf[t.head:]) |
| 62 | copy(out[n:], t.buf[:t.head]) |
| 63 | return out |
| 64 | } |
| 65 | |
| 66 | // String returns the buffer contents as a string. |
| 67 | func (t *TruncBuffer) String() string { |
no outgoing calls