serde

package
v1.27.8 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinArenaSize = 512
	MaxArenaSize = 4096
)

The size of a string arena is bounded, but not strictly by [min, max]:

  • Attempting to set a capacity below MinArenaSize will have no effect as beneath this limit it is not worth it. Calls to String with a capacity below this boundary will simply allocate.
  • An arena WILL be capped at MaxArenaSize.
View Source
const ArenaPayloadFactor = 4

ArenaPayloadFactor is the ratio at which we size string arenas to the payload (clamped by StringArenaMin/Max)

We limit arenas to 4k but smaller payloads likely don't need it, so we size down (somewhat arbitrarily) until we hit the 512-byte floor at which we just don't arena.

Variables

This section is empty.

Functions

func ReadPayloadBlob added in v1.27.7

func ReadPayloadBlob(r io.Reader, contentLength int64) (*bytes.Buffer, error)

ReadPayloadBlob consumes the given reader into a buffer that does not come from (and will never be returned to) a pool, sizing it from contentLength when that is known and within bounds.

Types

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a generic slice-backed stack pre-allocated to avoid growth allocations for typical serde nesting depths.

func NewStack

func NewStack[T any]() Stack[T]

NewStack returns a Stack pre-allocated with capacity 8.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len returns the number of elements in the stack.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes and returns the top value.

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

Push adds a value to the top of the stack.

func (*Stack[T]) Reset

func (s *Stack[T]) Reset()

Reset clears the stack while retaining allocated capacity.

func (*Stack[T]) Top

func (s *Stack[T]) Top() *T

Top returns a pointer to the top value without removing it.

func (*Stack[T]) Values

func (s *Stack[T]) Values() []T

Values returns the underlying slice for indexed access.

type StringArena added in v1.27.7

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

StringArena batches many small string allocations into one block.

You MUST call Reset with the desired capacity before use. Failure to do so will mean any calls to String will simply allocate and you won't get the performance benefit of the arena.

func (*StringArena) Reset added in v1.27.7

func (a *StringArena) Reset(cap int)

Reset prepares the arena for a new document, sizing its next block to cap.

func (*StringArena) String added in v1.27.7

func (a *StringArena) String(b []byte) string

String attempts to intern a copy of b in the arena, returning a string slice for it.

If the arena is at capacity, it will just allocate a new string.

Jump to

Keyboard shortcuts

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