buffer

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package buffer implements a buffer for serialization, consisting of a chain of []byte-s to reduce copying and to allow reuse of individual chunks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {

	// Buf is a byte buffer to use in append-like workloads.
	// See example code for details.
	Buf []byte
}

Buffer is a buffer optimized for serialization without extra copying.

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(data byte)

AppendByte appends a single byte to buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(data []byte)

AppendBytes appends a byte slice to buffer.

func (*Buffer) AppendString

func (b *Buffer) AppendString(data string)

AppendString appends a string to buffer.

func (*Buffer) BuildBytes

func (b *Buffer) BuildBytes(reuse ...[]byte) []byte

BuildBytes creates a single byte slice with all the contents of the buffer. Data is copied if it does not fit in a single chunk. You can optionally provide one byte slice as argument that it will try to reuse.

func (*Buffer) Bytes

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

Bytes returns b.Buf, i.e. all the bytes accumulated in the buffer.

The purpose of this function is bytes.Buffer compatibility.

func (*Buffer) DumpTo

func (b *Buffer) DumpTo(w io.Writer) (written int, err error)

DumpTo outputs the contents of a buffer to a writer and resets the buffer.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the size of the byte buffer.

func (*Buffer) ReadCloser

func (b *Buffer) ReadCloser() io.ReadCloser

ReadCloser creates an io.ReadCloser with all the contents of the buffer.

func (*Buffer) ReadFrom

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

ReadFrom implements io.ReaderFrom.

The function appends all the data read from r to b.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset makes ByteBuffer.Buf empty.

func (*Buffer) Set

func (b *Buffer) Set(p []byte)

Set sets ByteBuffer.Buf to p.

func (*Buffer) SetString

func (b *Buffer) SetString(s string)

SetString sets ByteBuffer.Buf to s.

func (*Buffer) Size

func (b *Buffer) Size() int

Size computes the size of a buffer by adding sizes of every chunk.

func (*Buffer) String

func (b *Buffer) String() string

String returns string representation of ByteBuffer.Buf.

func (*Buffer) Write

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

Write implements io.Writer - it appends p to ByteBuffer.Buf

func (*Buffer) WriteByte

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

WriteByte appends the byte c to the buffer.

The purpose of this function is bytes.Buffer compatibility.

The function always returns nil.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (int, error)

WriteString appends s to ByteBuffer.Buf.

func (*Buffer) WriteTo

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

WriteTo implements io.WriterTo.

Jump to

Keyboard shortcuts

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