google永远的神

This commit is contained in:
impact-eintr
2021-09-05 21:53:52 +08:00
parent 0a08ba8692
commit b851ceba7f
6 changed files with 262 additions and 4 deletions

View File

@@ -8,3 +8,24 @@ type Prependable struct {
func NewPrependable(size int) Prependable {
return Prependable{}
}
func NewPrependableFromView(v View) Prependable {
return Prependable{buf: v, usedIdx: 0}
}
func (p Prependable) View() View {
return p.buf[p.usedIdx:]
}
func (p Prependable) UsedLength() inty {
return len(p.buf) - p.usedIdx
}
func (p *Prependable) Prepend(size int) []byte {
if size > p.usedIdx {
return nil
}
p.usedIdx -= size
return p.View()[:size:size]
}