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 ¶
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 ¶
MarshalVarArray marshals a byte slice into a variable-length array format. It escapes delimiter and escape characters within the source slice.
func UnmarshalVarArray ¶
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.