Documentation ¶
Index ¶
- func Bytes2StringRef(b []byte) string
- func Prefix(b []byte, length int) []byte
- func String2BytesRef(s string) []byte
- func Sub(b []byte, index int, length int) []byte
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) DebugString() string
- func (b *Buffer) Flush(n int)
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Peek(n int) []byte
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) ReserveBytes(n int) []byte
- func (b *Buffer) Reset()
- func (b *Buffer) ResetAndFree()
- func (b *Buffer) Skip(n int)
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) WritableBytes() []byte
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteString(s string) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes2StringRef ¶ added in v0.28.0
func String2BytesRef ¶ added in v0.28.0
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer 先进先出可扩容流式buffer,可直接读写内部切片避免拷贝
部分Api示例:
读取方式1 buf := Bytes() ... // 读取buf的内容 Skip(n) 读取方式2 buf := Peek(n) ... 读取方式3 buf := make([]byte, n) nn, err := Read(buf) 读取方式4 ... String() ... 写入方式1 Grow(n) buf := WritableBytes()[:n] ... // 向buf中写入内容 Flush(n) // 或者直接 buf := ReserveBytes(n) ... // 向buf中写入内容 Flush(n) 写入方式2 n, err := Write(buf) 写入方式3 ... WriteString() ...
func (*Buffer) DebugString ¶
func (*Buffer) ReserveBytes ¶
ReserveBytes
返回可写入`n`大小的字节切片,如果空闲空间不够,内部会进行扩容。
注意,一般在完成写入后,需要调用 Flush。
@return: 注意,返回值空间大小只会为`n`。
func (*Buffer) ResetAndFree ¶ added in v0.30.3
func (b *Buffer) ResetAndFree()
ResetAndFree 重置并不再持有底层内存块
Click to show internal directories.
Click to hide internal directories.