mirror of
https://github.com/antonmedv/fx
synced 2024-11-15 12:13:06 +00:00
33 lines
479 B
Go
33 lines
479 B
Go
package model
|
|
|
|
type ring struct {
|
|
buf [100]byte
|
|
start, end int
|
|
}
|
|
|
|
func (r *ring) writeByte(b byte) {
|
|
if b == '\n' {
|
|
r.end = 0
|
|
r.start = r.end
|
|
return
|
|
}
|
|
r.buf[r.end] = b
|
|
r.end++
|
|
if r.end >= len(r.buf) {
|
|
r.end = 0
|
|
}
|
|
if r.end == r.start {
|
|
r.start++
|
|
if r.start >= len(r.buf) {
|
|
r.start = 0
|
|
}
|
|
}
|
|
}
|
|
|
|
func (r *ring) string() string {
|
|
if r.start < r.end {
|
|
return string(r.buf[r.start:r.end])
|
|
}
|
|
return string(r.buf[r.start:]) + string(r.buf[:r.end])
|
|
}
|