mirror of
https://github.com/impact-eintr/netstack.git
synced 2025-10-05 12:56:55 +08:00
google永远的神
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
Reference in New Issue
Block a user