Len returns the number of bytes currently stored in the buffer.
()
| 180 | // Len returns the number of bytes currently stored in the |
| 181 | // buffer. |
| 182 | func (b *HeadTailBuffer) Len() int { |
| 183 | b.mu.Lock() |
| 184 | defer b.mu.Unlock() |
| 185 | |
| 186 | tailLen := 0 |
| 187 | if b.tailFull { |
| 188 | tailLen = b.maxTail |
| 189 | } else if b.tail != nil { |
| 190 | tailLen = b.tailPos |
| 191 | } |
| 192 | return len(b.head) + tailLen |
| 193 | } |
| 194 | |
| 195 | // TotalWritten returns the total number of bytes written to |
| 196 | // the buffer, which may exceed the stored capacity. |