Documentation ¶
Overview ¶
Package bytes2 provide some helpful functions and multiple bytes pools.
Index ¶
- Constants
- Variables
- func IsAllBytesIn(bs []byte, encoding []byte) bool
- func NewBuffer(size int) *bytes.Buffer
- func SplitAndTrim(s, sep []byte) [][]byte
- func TrimAfter(s []byte, delim []byte) []byte
- func TrimBefore(s []byte, delim []byte) []byte
- type FakePool
- type ListPool
- type Pool
- type SlotPool
- type SyncPool
Constants ¶
const DEF_BUFSIZE = 1024
DEF_BUFSIZE is default buffer size
Variables ¶
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 ¶
IsAllBytesIn check whether all bytes is in given encoding bytes
func SplitAndTrim ¶
SplitAndTrim split bytes array, and trim space on each section
func TrimBefore ¶
Types ¶
type ListPool ¶
ListPool is based on a linked list, will not expires, shrink by call ShrinkTo
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 ¶
SyncSlotPool create a SlotPool based on ListPool
func NewListPool ¶
func NewSlotPool ¶
func NewSyncPool ¶
func SyncSlotPool ¶
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