yamlwire

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 12 Imported by: 2 modules, 2 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 yamlwire provides bounded, explicit YAML 1.2 decoding and deterministic encoding.

Decoding rejects duplicate keys and multiple documents by default. Anchors, aliases, and merge keys are supported with resource limits; callers can reject aliases or merge keys for protocols that do not permit them. YAML is not included in wire.DetectFormat because reliable detection from arbitrary text is not possible.

Use Decode/Encode for the pinned YAML v4 mapping of YAML 1.2.2 with retained dependency compatibility rules, not cryptographic canonicalization. Reader calls buffer the stream and never close it. Inputs and custom codecs are borrowed, and target decoding can mutate before failure; serialize shared mutation. No context API, transport, schema, cgo or workers are introduced.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum YAML stream size.

Variables

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies YAML streams over the configured byte limit.

Functions

func Decode

func Decode(payload []byte, target any, options DecodeOptions) error

Decode parses a bounded YAML stream into target.

func DecodeReader

func DecodeReader(reader io.Reader, target any, options DecodeOptions) error

DecodeReader buffers a borrowed reader through EOF or size refusal before target decoding. Reader is never closed and there is no context API. Target must be a non-nil pointer; codec/strictness failures can leave it mutated. Keep custom codecs bounded and do not reuse a failed target without resetting it.

func Encode

func Encode(value any, options EncodeOptions) ([]byte, error)

Encode borrows a stable acyclic value and uses the pinned dumper with sorted mappings and block-scalar repair, not arbitrary YAML canonicalization. Custom node order/marshalers remain caller-owned. A bounded scratch stream can be up to twice the final byte quota before normalization; failure returns no payload.

func EncodeWriter

func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error

EncodeWriter completes serialization before touching a borrowed writer, which it never closes. Encoding failure writes nothing; a later write error can leave a prefix visible and matches wire.ErrWrite. It is not an atomic publication API.

Types

type DecodeOptions

type DecodeOptions struct {
	// MaxBytes caps supplied input bytes; zero selects DefaultMaxBytes; negative values fail.
	MaxBytes int64
	// MaxDepth adds an explicit positive depth limit; zero keeps dependency defaults, not
	// unlimited parsing.
	MaxDepth int
	// MaxAliases adds an explicit positive alias-count limit; zero keeps dependency
	// protections.
	MaxAliases int
	// DisallowUnknownFields requests known-field checking for struct destinations.
	DisallowUnknownFields bool
	// AllowDuplicateKeys opts out of unique-key rejection in the pinned YAML loader.
	AllowDuplicateKeys bool
	// AllowMultipleDocuments decodes all documents into a slice target; false requires exactly
	// one document.
	AllowMultipleDocuments bool
	// DisallowAliases refuses aliases regardless of MaxAliases; anchors themselves remain
	// permitted.
	DisallowAliases bool
	// DisallowMergeKeys refuses merge-tag nodes during preflight before target loading.
	DisallowMergeKeys bool
}

DecodeOptions controls YAML parsing, interoperability, and resource limits. Zero limits retain safe library defaults. AllowMultipleDocuments requires a pointer to a slice and decodes every document into that slice.

type EncodeOptions

type EncodeOptions struct {
	// MaxBytes caps returned encoded bytes; zero selects DefaultMaxBytes; negative values fail.
	MaxBytes int64
	// Indent selects 2..9 columns; zero selects the pinned dumper default of two.
	Indent int
	// DefaultSequenceIndent disables compact sequence indentation in the pinned dumper.
	DefaultSequenceIndent bool
}

EncodeOptions controls deterministic YAML serialization.

Jump to

Keyboard shortcuts

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