buffer

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBufferSize buffer size created by default
	DefaultBufferSize = 1024 * 256
	// DefaultReadBlockSize default read block size
	DefaultReadBlockSize = 8192
	// DefaultWriteBlockSize default write block size
	DefaultWriteBlockSize = 8192
)

Variables

View Source
var (
	// ErrInsufficientData buffer has insufficient data
	ErrInsufficientData = errors.New("buffer has insufficient data")

	// ErrInsufficientSpace buffer has insufficient space
	ErrInsufficientSpace = errors.New("buffer has insufficient space")

	// ErrNotReady buffer is not ready yet
	ErrNotReady = errors.New("buffer is not ready")
)

Functions

This section is empty.

Types

type Type

type Type struct {
	ExternalBuf []byte
	// contains filtered or unexported fields
}

Type of buffer align atomic values to prevent panics on 32 bits macnines see https://github.com/golang/go/issues/5278

func New

func New(size int64) (*Type, error)

New buffer

func (*Type) Close

func (b *Type) Close() error

Close buffer

func (*Type) ID

func (b *Type) ID() int64

ID of buffer

func (*Type) Len

func (b *Type) Len() int

Len of data

func (*Type) Read

func (b *Type) Read(p []byte) (int, error)

Read data

func (*Type) ReadCommit

func (b *Type) ReadCommit(n int) (int, error)

ReadCommit Commit moves the cursor forward by n bytes. It behaves like Read() except it doesn't return any data. If there's enough data, then the cursor will be moved forward and n will be returned. If there's not enough data, then the cursor will move forward as much as possible, then return the number of positions (bytes) moved.

func (*Type) ReadFrom

func (b *Type) ReadFrom(r io.Reader) (int64, error)

ReadFrom from reader

func (*Type) ReadPeek

func (b *Type) ReadPeek(n int) ([]byte, error)

ReadPeek Description below is copied completely from bufio.Peek()

http://golang.org/pkg/bufio/#Reader.Peek

Peek returns the next n bytes without advancing the reader. The bytes stop being valid at the next read call. If Peek returns fewer than n bytes, it also returns an error explaining why the read is short. The error is bufio.ErrBufferFull if n is larger than b's buffer size. If there's not enough data to peek, error is ErrBufferInsufficientData. If n < 0, error is bufio.ErrNegativeCount

func (*Type) ReadWait

func (b *Type) ReadWait(n int) ([]byte, error)

ReadWait waits for for n bytes to be ready. If there's not enough data, then it will wait until there's enough. This differs from ReadPeek or Readin that Peek will return whatever is available and won't wait for full count.

func (*Type) Send

func (b *Type) Send(from [][]byte) (int, error)

Send to

func (*Type) Size

func (b *Type) Size() int64

Size of buffer

func (*Type) Write

func (b *Type) Write(p []byte) (int, error)

Write message

func (*Type) WriteCommit

func (b *Type) WriteCommit(n int) (int, error)

WriteCommit write with commit

func (*Type) WriteTo

func (b *Type) WriteTo(w io.Writer) (int64, error)

WriteTo to writer

func (*Type) WriteWait

func (b *Type) WriteWait(n int) ([]byte, bool, error)

WriteWait waits for n bytes to be available in the buffer and then returns 1. the slice pointing to the location in the buffer to be filled 2. a boolean indicating whether the bytes available wraps around the ring 3. any errors encountered. If there's error then other return values are invalid

Jump to

Keyboard shortcuts

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