func (b *Buffer) Avail(count int) bool {
	return count <= b.available
}
Avail checks if count bytes are available for reading from the buffer.
package streambuf
import (
	"github.com/elastic/beats/libbeat/logp"
	"bytes"
	"errors"
)
var ErrOperationNotAllowed = errors.New("Operation not allowed")
var ErrOutOfRange = errors.New("Data access out of range")
var ErrNoMoreBytes = errors.New("No more bytes")
var ErrUnexpectedEOB = errors.New("unexpected end of buffer")
var ErrExpectedByteSequenceMismatch = errors.New("expected byte sequence did not match")
type Buffer struct {
	data  []byte
	err   error
	fixed bool
	mark, offset, available int
}
func (b *Buffer) Init(d []byte, fixed bool) {
	b.data = d
	b.err = nil
	b.fixed = fixed
	b.mark = 0
	b.offset = 0
	b.available = len(d)
}
func New(data []byte) *Buffer {
	return &Buffer{
		data:      data,
		fixed:     false,
		available: len(data),
	}
}
func NewFixed(data []byte) *Buffer {
	return &Buffer{
		data:      data,
		fixed:     true,
		available: len(data),
	}
}
func (b *Buffer) Snapshot() *Buffer {
	tmp := *b
	return &tmp
}
func (b *Buffer) Restore(snapshot *Buffer) {
	b.err = snapshot.err
	b.fixed = snapshot.fixed
	b.mark = snapshot.mark
	b.offset = snapshot.offset
	b.available = snapshot.available
}
func (b *Buffer) doAppend(data []byte, retainable bool, newCap int) error {
	if b.fixed {
		return b.SetError(ErrOperationNotAllowed)
	}
	if b.err != nil && b.err != ErrNoMoreBytes {
		return b.err
	}
	if len(b.data) == 0 {
		retain := retainable && cap(data) > newCap
		if retain {
			b.data = data
		} else {
			if newCap < len(data) {
				b.data = make([]byte, len(data))
			} else {
				b.data = make([]byte, len(data), newCap)
			}
			copy(b.data, data)
		}
	} else {
		if newCap > 0 && cap(b.data[b.offset:]) < len(data) {
			required := cap(b.data) + len(data)
			if required < newCap {
				tmp := make([]byte, len(b.data), newCap)
				copy(tmp, b.data)
				b.data = tmp
			}
		}
		b.data = append(b.data, data...)
	}
	b.available += len(data)
	if b.err == ErrNoMoreBytes {
		b.err = nil
	}
	return nil
}
func (b *Buffer) Append(data []byte) error {
	return b.doAppend(data, true, -1)
}
func (b *Buffer) AppendWithCapLimits(data []byte, newCap int) error {
	return b.doAppend(data, true, newCap)
}
func (b *Buffer) Fix() {
	b.fixed = true
}
func (b *Buffer) Total() int {
	return len(b.data)
}