bytes2

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package bytes2 provide some helpful functions and multiple bytes pools.

Index

Constants

View Source
const DEF_BUFSIZE = 1024

DEF_BUFSIZE is default buffer size

Variables

View Source
var CanPool = func(cap, bufsize int, allowsmall bool) bool {
	return cap >= bufsize || (allowsmall && cap >= bufsize>>1)
}

CanPool is the default checker to check whether a buffer is reuseable, if the buffer's capacity is less than half of default bufsize or small buffer was not allowed, it will be dropped

Functions

func IsAllBytesIn

func IsAllBytesIn(bs, encoding []byte) bool

IsAllBytesIn check whether all bytes is in given encoding bytes

func MultipleLineOperate added in v0.2.3

func MultipleLineOperate(s, delim []byte, operate func(line, delim []byte) []byte) []byte

func NewBuffer

func NewBuffer(size int) *bytes.Buffer

func SplitAndTrim

func SplitAndTrim(s, sep []byte) [][]byte

SplitAndTrim split bytes array, and trim space on each section

func TrimAfter

func TrimAfter(s, delim []byte) []byte

TrimAfter remove bytes after delimeter, and trim space on remains

func TrimBefore

func TrimBefore(s, delim []byte) []byte

func TrimFirstN added in v0.2.3

func TrimFirstN(s, delim []byte, n int) []byte

func TrimLastN added in v0.2.3

func TrimLastN(s, delim []byte, n int) []byte

Types

type FakePool

type FakePool struct{}

FakePool is a fake pool, it isn't a actual pool

func (FakePool) Get

func (p FakePool) Get(size int, asLen bool) []byte

func (FakePool) Put

func (p FakePool) Put([]byte)

func (FakePool) TryPut

func (p FakePool) TryPut([]byte) bool

type ListPool

type ListPool struct {
	Count int
	sync.Mutex
	// contains filtered or unexported fields
}

ListPool is based on a linked list, will not expires, shrink by call ShrinkTo

func (*ListPool) Get

func (p *ListPool) Get(size int, asLen bool) []byte

func (*ListPool) Put

func (p *ListPool) Put(buf []byte)

func (*ListPool) ShrinkTo

func (p *ListPool) ShrinkTo(count int)

ShrinkTo cause the ListPool's buffer count reduce to count

func (*ListPool) TryPut

func (p *ListPool) TryPut(buf []byte) bool

type Pool

type Pool interface {
	// Get a buffer, capacity is at least the given size if asLen, length will
	// be set to size, else 0
	Get(size int, asLen bool) []byte
	Put(buf []byte)
	// TryPut will pool the buffer, return whether buffer was pooled by CanPool function
	TryPut(buf []byte) bool
}

func ListSlotPool

func ListSlotPool(slot, bufsize int, allowsmall bool) Pool

SyncSlotPool create a SlotPool based on ListPool

func NewFakePool added in v0.2.3

func NewFakePool() Pool

func NewListPool

func NewListPool(bufsize int, allowsmall bool) Pool

func NewSlotPool

func NewSlotPool(pools []Pool) Pool

func NewSyncPool

func NewSyncPool(bufsize int, allowsmall bool) Pool

func SyncSlotPool

func SyncSlotPool(slot, bufsize int, allowsmall bool) Pool

SyncSlotPool create a SlotPool based on SyncPool

type SlotPool

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

SlotPool is a slice of Pool, it will truncate pools size to power of 2, each Get/Put will cycle through the pools

func (*SlotPool) Get

func (p *SlotPool) Get(size int, asLen bool) []byte

func (*SlotPool) Put

func (p *SlotPool) Put(buf []byte)

func (*SlotPool) TryPut

func (p *SlotPool) TryPut(buf []byte) bool

type SyncPool

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

SyncPool is based on sync.Pool

func (*SyncPool) Get

func (p *SyncPool) Get(size int, asLen bool) []byte

func (*SyncPool) Put

func (p *SyncPool) Put(buf []byte)

func (*SyncPool) TryPut

func (p *SyncPool) TryPut(buf []byte) bool

Jump to

Keyboard shortcuts

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