bytesx

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bytesx extends the bytes package.

Index

Examples

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
}

Buffer wraps a byte slice, providing convenience functions.

Example
package main

import (
	"fmt"

	"github.com/hamba/pkg/bytesx"
)

func main() {
	p := bytesx.NewPool(1024) // A Buffer is returned from a pool

	buf := p.Get() // Buffer is Reset when getting it

	buf.WriteString("Hello")
	buf.Write([]byte(" World!"))

	fmt.Println(buf.String())

	p.Put(buf) // Release the buffer back to the pool

}
Output:

Hello World!

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool appends a bool to the underlying buffer.

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64, fmt byte, prec, bitSize int)

AppendFloat appends a float to the underlying buffer.

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

AppendInt appends an integer to the underlying buffer.

func (*Buffer) AppendTime

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

AppendTime appends a time to the underlying buffer, in the given layout.

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

AppendUint appends an unsigned integer to the underlying buffer.

func (*Buffer) Bytes

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

Bytes returns a mutable reference to the underlying byte slice.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the underlying byte slice.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the underlying byte slice.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the underlying byte slice. Subsequent writes re-use the slice's backing array.

func (*Buffer) String

func (b *Buffer) String() string

String returns a string of the underlying byte slice.

func (*Buffer) Write

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

Write implements io.Writer.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(v byte) error

WriteByte writes a single byte to the Buffer.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string)

WriteString writes a string to the Buffer.

type Pool

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

Pool is a pool of Buffers.

func NewPool

func NewPool(size int) Pool

NewPool creates a new instance of Pool.

size is the initial size of a new Buffer.

func (Pool) Get

func (p Pool) Get() *Buffer

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

func (Pool) Put

func (p Pool) Put(buf *Buffer)

Put adds a Buffer to the pool.

Jump to

Keyboard shortcuts

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