bytes

package
v0.0.0-...-f9b9731 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteArrayToString

func ByteArrayToString(buf []byte) string

ByteArrayToString turns a slice of bytes to string, without extra memory allocations

NOTE! Using this function is extremely dangerous, so it can be done with extra care with clear understanding how it works

func BytesCopy

func BytesCopy(src []byte) []byte

BytesCopy makes a copy of src slice of bytes

func StringToByteArray

func StringToByteArray(v string) []byte

StringToByteArray gets a string and turn it to []byte without extra memoy allocations

NOTE! Using this function is extremely dangerous, so it can be done with extra care with clear understanding how it works

Types

type Pool

type Pool struct {
}

Pool manages a pool of slices of bytes. It is supposed to use the pool in highly loaded apps where slice of bytes are needed often. An example could be handling a network packages.

func (*Pool) Arrange

func (p *Pool) Arrange(size int) []byte

Arrange returns a slice by the size requested. The function could return the slice with capacity bigger than the size provided.

func (*Pool) Release

func (p *Pool) Release(buf []byte)

Release allows to place the buffer to appropriate pool for next usage

type Writer

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

Writer struct support io.Writer interface and allows to write data into extendable underlying buffer. It uses Pool for arranging new buffers.

The Writer MUST not be copied.

func (*Writer) Buf

func (w *Writer) Buf() []byte

Buf returns underlying written buffer

func (*Writer) Close

func (w *Writer) Close() error

Close releases resources and makes w unusable

func (*Writer) Init

func (w *Writer) Init(initSz int, p *Pool)

Init initilizes the Writer to use Pool p and initialize the w.buf to specified size

func (*Writer) Reset

func (w *Writer) Reset()

Reset drops the pos to 0, but it doesn't touch underlying buffer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write is part of io.Writer

func (*Writer) WriteByte

func (w *Writer) WriteByte(b byte)

WriteByte writes one byte to the buffer

func (*Writer) WriteString

func (w *Writer) WriteString(s string)

WriteString writes string to the buffer

Jump to

Keyboard shortcuts

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