karmem

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: BSD-3-Clause Imports: 2 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutOfMemory happens when alloc is required while using NewFixedWriter.
	ErrOutOfMemory = errors.New("out-of-memory, FixedWriter can't reallocate")
)

Functions

This section is empty.

Types

type Reader

type Reader struct {
	Memory   []byte
	Pointer  unsafe.Pointer
	Size     uint64
	Min, Max uintptr
}

Reader holds the buffer to read data from.

func NewReader

func NewReader(mem []byte) *Reader

NewReader creates a Reader using the existent slice. The slice is supposed to have, and begin with, a Karmem encoded structure.

Reader is not current safe. You MUST not change the slice content while reading.

func (*Reader) IsValidOffset

func (m *Reader) IsValidOffset(ptr, size uint32) bool

IsValidOffset check if the current offset and size is valid and accessible within the bounds.

func (*Reader) SetSize

func (m *Reader) SetSize(size uint32) bool

SetSize re-defines the bounds of the slice, useful when the backend slice is being re-used for multiples contents.

type Writer

type Writer struct {
	Memory []byte
	// contains filtered or unexported fields
}

Writer holds the encoded, the finished encode can be retrieved by Writer.Bytes()

func NewFixedWriter

func NewFixedWriter(mem []byte) *Writer

NewFixedWriter creates a Writer from an existent memory segment/buffer. The memory can't be resized.

func NewWriter

func NewWriter(capacity int) *Writer

NewWriter creates a Writer with the given initial capacity.

func (*Writer) Alloc

func (w *Writer) Alloc(n uint) (uint, error)

Alloc allocates n bytes inside. It returns the offset and may return error if it's not possible to allocate.

func (*Writer) Bytes

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

Bytes return the Karmem encoded bytes. It doesn't copy the content, and can't be re-used after Reset.

func (*Writer) Reset

func (w *Writer) Reset()

Reset will reset the memory length, but keeps the memory capacity.

func (*Writer) Write1At

func (w *Writer) Write1At(offset uint, data uint8)

Write1At copies the given one-byte data into the Writer memory.

func (*Writer) Write2At

func (w *Writer) Write2At(offset uint, data uint16)

Write2At copies the given two-byte data into the Writer memory.

func (*Writer) Write4At

func (w *Writer) Write4At(offset uint, data uint32)

Write4At copies the given four-byte data into the Writer memory.

func (*Writer) Write8At

func (w *Writer) Write8At(offset uint, data uint64)

Write8At copies the given eight-byte data into the Writer memory.

func (*Writer) WriteAt

func (w *Writer) WriteAt(offset uint, data []byte)

WriteAt copies the given data into the Writer memory.

Jump to

Keyboard shortcuts

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