package bytebufferpoolimport// ByteBuffer provides byte buffer, which can be used for minimizing// memory allocations.//// ByteBuffer may be used with functions appending data to the given []byte// slice. See example code for details.//// Use Get for obtaining an empty byte buffer.typeByteBufferstruct {// B is a byte buffer to use in append-like workloads. // See example code for details. B []byte}// Len returns the size of the byte buffer.func ( *ByteBuffer) () int {returnlen(.B)}// ReadFrom implements io.ReaderFrom.//// The function appends all the data read from r to b.func ( *ByteBuffer) ( io.Reader) (int64, error) { := .B := int64(len()) := int64(cap()) := if == 0 { = 64 = make([]byte, ) } else { = [:] }for {if == { *= 2 := make([]byte, )copy(, ) = } , := .Read([:]) += int64()if != nil { .B = [:] -= if == io.EOF {return , nil }return , } }}// WriteTo implements io.WriterTo.func ( *ByteBuffer) ( io.Writer) (int64, error) { , := .Write(.B)returnint64(), }// Bytes returns b.B, i.e. all the bytes accumulated in the buffer.//// The purpose of this function is bytes.Buffer compatibility.func ( *ByteBuffer) () []byte {return .B}// Write implements io.Writer - it appends p to ByteBuffer.Bfunc ( *ByteBuffer) ( []byte) (int, error) { .B = append(.B, ...)returnlen(), nil}// WriteByte appends the byte c to the buffer.//// The purpose of this function is bytes.Buffer compatibility.//// The function always returns nil.func ( *ByteBuffer) ( byte) error { .B = append(.B, )returnnil}// WriteString appends s to ByteBuffer.B.func ( *ByteBuffer) ( string) (int, error) { .B = append(.B, ...)returnlen(), nil}// Set sets ByteBuffer.B to p.func ( *ByteBuffer) ( []byte) { .B = append(.B[:0], ...)}// SetString sets ByteBuffer.B to s.func ( *ByteBuffer) ( string) { .B = append(.B[:0], ...)}// String returns string representation of ByteBuffer.B.func ( *ByteBuffer) () string {returnstring(.B)}// Reset makes ByteBuffer.B empty.func ( *ByteBuffer) () { .B = .B[:0]}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.