2024-03-26 08:45:18 +01:00
|
|
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
|
|
// All rights reserved.
|
|
|
|
|
2024-03-26 07:00:53 +01:00
|
|
|
// byte-slider.go
|
|
|
|
package expr
|
|
|
|
|
|
|
|
import "bytes"
|
|
|
|
|
|
|
|
type ByteSlider struct {
|
|
|
|
buf []byte
|
|
|
|
length int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewByteSlider(size int) *ByteSlider {
|
|
|
|
return &ByteSlider{
|
|
|
|
buf: make([]byte, max(1, size)),
|
|
|
|
length: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *ByteSlider) PushEnd(b byte) {
|
|
|
|
if self.length == cap(self.buf) {
|
|
|
|
self.length--
|
|
|
|
for i := 0; i < self.length; i++ {
|
|
|
|
self.buf[i] = self.buf[i+1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.buf[self.length] = b
|
|
|
|
self.length++
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *ByteSlider) Equal(target []byte) bool {
|
|
|
|
return target != nil && bytes.Equal(self.buf, target)
|
|
|
|
}
|