4.0初步改造

This commit is contained in:
dexter
2022-02-02 10:39:09 +08:00
parent 6ace71fac6
commit b2489b2305
59 changed files with 6192 additions and 2061 deletions

30
util/buffer.go Normal file
View File

@@ -0,0 +1,30 @@
package util
type Buffer []byte
func (b *Buffer) Write(a []byte) (n int, err error) {
*b = append(*b, a...)
return len(a), nil
}
func (b Buffer) Len() int {
return len(b)
}
func (b Buffer) Cap() int {
return cap(b)
}
func (b Buffer) SubBuf(start int, length int) Buffer {
return b[start : start+length]
}
func (b *Buffer) Malloc(count int) Buffer {
l := b.Len()
if l+count > b.Cap() {
n := make(Buffer, l+count)
copy(n, *b)
*b = n
}
return b.SubBuf(l, count)
}
func (b *Buffer) Reset() {
*b = b.SubBuf(0, 0)
}