Help us shape the future of Go! Take the 2026 Go Developer Survey

bufferpool

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 4 Imported by: 9

README

go-bufferpool

Usage

import "github.com/Xuanwo/go-bufferpool"

var pool = bufferpool.New(1024)

func main() {
    buf := pool.Get()
    defer buf.Free()

    buf.AppendString("Hello, World!")

    buf.String() // "Hello, World!"
}

References

Inspired by following projects:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool will append a bool into buffer.

true => "true" false => "false"

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte will append a byte into buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(v []byte)

AppendBytes will append an bytes slice into buffer.

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64)

AppendFloat will append a float64 into buffer.

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

AppendInt will append an int64 into buffer.

func (*Buffer) AppendRune

func (b *Buffer) AppendRune(r rune)

AppendRune will append a rune into buffer.

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

AppendString will append a string into buffer.

func (*Buffer) AppendTime

func (b *Buffer) AppendTime(t time.Time, layout string)

AppendTime will append time with input layout.

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

AppendUint will append a uint64 into buffer.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes will return underlying bytes.

func (*Buffer) BytesCopy

func (b *Buffer) BytesCopy() []byte

BytesCopy will return copied underlying bytes.

func (*Buffer) Free

func (b *Buffer) Free()

Free will free underlying bytes and put into pool.

After free, this buffer should not be touched anymore.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset will reset underlying buffer.

func (*Buffer) String added in v0.2.0

func (b *Buffer) String() string

String will convert underlying bytes to string and return.

func (*Buffer) Write

func (b *Buffer) Write(bs []byte) (int, error)

Write implements io.Writer to support write into buffer.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a type-safe wrapper around a sync.Pool.

func New

func New(size int) *Pool

New constructs a new Pool.

func (*Pool) Get

func (p *Pool) Get() *Buffer

Get retrieves a Buffer from the pool, creating one if necessary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL