vararray

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 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 vararray holds the escaped, delimiter-separated variable-length array codec (MarshalVarArray / UnmarshalVarArray and the delimiter/escape bytes). It is a dependency-free leaf (imports only stdlib), so consumers that need only this codec — e.g. the plugin SDK at pkg/pipeline/sdk — can use it without transitively pulling in pkg/encoding's logging dependencies. pkg/encoding forwards to these functions, so existing encoding.*VarArray callers are unaffected.

Index

Constants

View Source
const (
	// EntityDelimiter is the delimiter for entities in a variable-length array.
	EntityDelimiter = '|'
	// Escape is the escape character for entities in a variable-length array.
	Escape = '\\'
)

Variables

This section is empty.

Functions

func MarshalVarArray

func MarshalVarArray(dest, src []byte) []byte

MarshalVarArray marshals a byte slice into a variable-length array format. It escapes delimiter and escape characters within the source slice.

func UnmarshalVarArray

func UnmarshalVarArray(src []byte, idx int) (int, int, error)

UnmarshalVarArray unmarshals a variable-length array from src starting at idx.

WARNING: This function mutates src when the entry contains an escape. Decoding is then performed in-place by overwriting bytes in src[idx:next) to remove escape characters. The decoded value is the view src[idx:end] into the same backing array; copy it (for example, with bytes.Clone or append([]byte(nil), ...)) if you need to preserve the original encoded buffer or keep the decoded value independent of subsequent in-place decoding on the same buffer.

An entry with no escape byte is decoded without writing to src at all. Do NOT read that as "src is safe from mutation": whether a write happens is a property of the DATA, not of the call. A caller may only skip its defensive copy behind its own escape check (e.g. bytes.IndexByte(row, Escape) < 0) — never unconditionally.

It returns:

  • end: the index of the first byte after the decoded value (exclusive)
  • next: the index of the next element (the byte after the delimiter)

The caller can iterate without creating subslices by tracking indices:

for idx < len(src) {
    end, next, err := UnmarshalVarArray(src, idx)
    // use src[idx:end]
    idx = next
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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