lazybytes

package
v0.1.3-testnet Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package lazybytes is a way to treat byte data as serialized arrays or, recursively, as trees of byte slices It is used for fast, safe and uniform serialization/deserialization in 'lazy' way: the bytes are only deserialized when there's a need to access element of the array or a tree The read-only lazy array and tree are thread safe. Non-read only are not thread safe It is used for the (de)serialization of Proxima transactions into the tree form, where every element (a byte slice) can be accessed with a path of indices (bytes)

Index

Constants

View Source
const MaxElementsLazyTree = 256

MaxElementsLazyTree each node of the tree can have maximum 256 elements

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

func ArrayFromBytesReadOnly

func ArrayFromBytesReadOnly(data []byte, maxNumElements ...int) *Array

func EmptyArray

func EmptyArray(maxNumElements ...int) *Array

EmptyArray by default mutable

func MakeArrayFromDataReadOnly

func MakeArrayFromDataReadOnly(element ...[]byte) *Array

func MakeArrayReadOnly

func MakeArrayReadOnly(element ...any) *Array

func ParseArrayFromBytesReadOnly

func ParseArrayFromBytesReadOnly(data []byte, maxNumElements ...int) (*Array, error)

func (*Array) AsTree

func (a *Array) AsTree() *Tree

func (*Array) At

func (a *Array) At(idx int) []byte

func (*Array) AtSafe

func (a *Array) AtSafe(idx int) ([]byte, error)

func (*Array) Bytes

func (a *Array) Bytes() []byte

func (*Array) ForEach

func (a *Array) ForEach(fun func(i int, data []byte) bool)

func (*Array) NumElements

func (a *Array) NumElements() int

func (*Array) Parsed

func (a *Array) Parsed() [][]byte

func (*Array) ParsedString

func (a *Array) ParsedString() string

func (*Array) Push

func (a *Array) Push(data []byte) int

func (*Array) PutAtIdx

func (a *Array) PutAtIdx(idx byte, data []byte)

PutAtIdx puts data at index, panics if array has no element at that index

func (*Array) PutAtIdxWithPadding

func (a *Array) PutAtIdxWithPadding(idx byte, data []byte)

PutAtIdxWithPadding puts data at index, pads elements with nils if necessary

func (*Array) SetData

func (a *Array) SetData(data []byte)

func (*Array) SetEmptyArray

func (a *Array) SetEmptyArray()

func (*Array) SetReadOnly

func (a *Array) SetReadOnly(ro bool) *Array

type Tree

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

Tree is a read only interface to Array, which is interpreted as a tree

func TreeEmpty

func TreeEmpty() *Tree

func TreeFromBytesReadOnly

func TreeFromBytesReadOnly(data []byte) *Tree

func TreeFromTreesReadOnly

func TreeFromTreesReadOnly(trees ...*Tree) *Tree

func (*Tree) Bytes

func (st *Tree) Bytes() []byte

Bytes recursively updates bytes in the tree from leaves

func (*Tree) BytesAtPath

func (st *Tree) BytesAtPath(path TreePath) []byte

BytesAtPath returns serialized for of the element at globalpath

func (*Tree) ForEach

func (st *Tree) ForEach(fun func(i byte, data []byte) bool, path TreePath)

func (*Tree) ForEachIndex

func (st *Tree) ForEachIndex(fun func(i byte) bool, path TreePath)

func (*Tree) NumElements

func (st *Tree) NumElements(path TreePath) int

NumElements returns number of elements of the Array at the end of globalpath

func (*Tree) Subtree

func (st *Tree) Subtree(path TreePath) *Tree

type TreePath

type TreePath []byte

func Path

func Path(p ...any) TreePath

func (TreePath) Bytes

func (p TreePath) Bytes() []byte

func (TreePath) Hex

func (p TreePath) Hex() string

func (TreePath) String

func (p TreePath) String() string

Jump to

Keyboard shortcuts

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