codecutil

package
v2.0.0-alpha.62 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codecutil owns the built-in codecs' bounded I/O, cancellation checkpoints, borrowed adoption callbacks, and acquired iterator cleanup. It does not change the public reader/writer contract.

Index

Constants

View Source
const ChunkSize = 4096

ChunkSize bounds payload writes and reader requests between checkpoints.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferWriter

type BufferWriter struct {
	Buffer *bytes.Buffer
	Writer
}

BufferWriter borrows an exact bytes.Buffer and shares all cancellation, error, and byte-accounting state with its embedded base writer.

func (*BufferWriter) Write

func (w *BufferWriter) Write(p []byte) (int, error)

func (*BufferWriter) WriteByte

func (w *BufferWriter) WriteByte(value byte) error

type Iterator

type Iterator struct {
	runtime.Iterator
	// contains filtered or unexported fields
}

Iterator owns only a distinct iterator acquired for encoding. An iterator sharing the borrowed source's identity remains with the source's owner.

func NewIterator

func NewIterator(ctx context.Context, source runtime.Iterable) (Iterator, error)

NewIterator acquires an iterator without taking ownership of the source.

func (*Iterator) Close

func (iter *Iterator) Close() error

Close releases an owned iterator once. Codecs call it after child encoding and join cleanup failures before running the parent's post-hooks.

type Operation

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

Operation samples traversal cancellation every 256 values or tokens. I/O and fallback boundaries can check directly without adding ctx.Err to hot loops.

func NewOperation

func NewOperation(ctx context.Context, input any, name string) (Operation, error)

NewOperation validates arguments and initializes borrowed operation state. Callers check cancellation explicitly: encoders first bind the adopter and discover the stored root; decoders check before hooks or reads.

func (*Operation) Adopt

func (op *Operation) Adopt(value runtime.Value, stored bool)

Adopt registers a visit, optionally discovering concrete stored descendants. Acquisition boundaries and abandoned containers request discovery; ordinary recursive visits register directly to keep hook-free traversal linear.

func (*Operation) CacheValueAdopter

func (op *Operation) CacheValueAdopter()

CacheValueAdopter binds a borrowed callback once after operation validation. It changes neither the cancellation lifetime nor the context passed to hooks.

func (*Operation) Check

func (op *Operation) Check() error

func (*Operation) HasValueAdopter

func (op *Operation) HasValueAdopter() bool

HasValueAdopter reports whether native values must pass through the visitor.

func (*Operation) Step

func (op *Operation) Step() error

type Reader

type Reader struct {
	Src io.Reader

	Op Operation
	// contains filtered or unexported fields
}

Reader observes non-EOF errors even when a decoder accepts accompanying data.

func (*Reader) Error

func (r *Reader) Error() error

func (*Reader) Input

func (r *Reader) Input() io.Reader

Input preserves ByteScanner support, avoiding an extra MessagePack buffer for byte readers. Scanner reads use sampled cancellation rather than per-byte checks.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

type Writer

type Writer struct {
	Dst io.Writer

	Op Operation
	// contains filtered or unexported fields
}

Writer detects short writes and stops forwarding after the first failure.

func (*Writer) Error

func (w *Writer) Error() error

func (*Writer) Write

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

func (*Writer) WriteByte

func (w *Writer) WriteByte(value byte) error

Jump to

Keyboard shortcuts

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