代码拉取完成,页面将自动刷新
package sys
// ByteBuffer is an expandable buffer backed by a byte slice.
type ByteBuffer struct {
buf []byte
offset int
}
// NewByteBuffer creates a new ByteBuffer with an initial capacity of
// initialSize.
func NewByteBuffer(initialSize int) *ByteBuffer {
return &ByteBuffer{buf: make([]byte, initialSize)}
}
// Write appends the contents of p to the buffer, growing the buffer as needed.
// The return value is the length of p; err is always nil.
func (b *ByteBuffer) Write(p []byte) (int, error) {
if len(b.buf) < b.offset+len(p) {
// Create a buffer larger than needed so we don't spend lots of time
// allocating and copying.
spaceNeeded := len(b.buf) - b.offset + len(p)
largerBuf := make([]byte, 2*len(b.buf)+spaceNeeded)
copy(largerBuf, b.buf[:b.offset])
b.buf = largerBuf
}
n := copy(b.buf[b.offset:], p)
b.offset += n
return n, nil
}
// Reset resets the buffer to be empty. It retains the same underlying storage.
func (b *ByteBuffer) Reset() {
b.offset = 0
b.buf = b.buf[:cap(b.buf)]
}
// Bytes returns a slice of length b.Len() holding the bytes that have been
// written to the buffer.
func (b *ByteBuffer) Bytes() []byte {
return b.buf[:b.offset]
}
// Len returns the number of bytes that have been written to the buffer.
func (b *ByteBuffer) Len() int {
return b.offset
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。