Size returns the current number of bytes in the buffer.
()
| 24 | |
| 25 | // Size returns the current number of bytes in the buffer. |
| 26 | func (rb *ringBuffer) Size() int { |
| 27 | if rb.end == -1 { |
| 28 | return 0 // Buffer is empty |
| 29 | } |
| 30 | if rb.start <= rb.end { |
| 31 | return rb.end - rb.start + 1 |
| 32 | } |
| 33 | // Buffer wraps around |
| 34 | return len(rb.buffer) - rb.start + rb.end + 1 |
| 35 | } |
| 36 | |
| 37 | // Write writes data to the ring buffer. If the buffer would overflow, |
| 38 | // it evicts the oldest data to make room for new data. |
no outgoing calls