yamlwire

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 12 Imported by: 0

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.

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 reads a bounded YAML stream and decodes it into target.

func Encode

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

Encode serializes value deterministically using sorted mapping keys.

func EncodeWriter

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

EncodeWriter serializes value and writes one complete YAML document.

Types

type DecodeOptions

type DecodeOptions struct {
	MaxBytes               int64
	MaxDepth               int
	MaxAliases             int
	DisallowUnknownFields  bool
	AllowDuplicateKeys     bool
	AllowMultipleDocuments bool
	DisallowAliases        bool
	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              int64
	Indent                int
	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