tomlwire

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: 11 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 tomlwire provides bounded, strict TOML document decoding and deterministic encoding.

TOML duplicate keys and malformed trailing text are always rejected. Datetime values use time.Time and TOML local date/time types according to the underlying decoder. Numeric conversions reject overflow and precision loss. TOML is not included in wire.DetectFormat because arbitrary text cannot be identified reliably.

Use Decode/Encode for the pinned TOML 1.1.0 codec contract; an empty document is valid. Reader calls buffer the document and never close the reader. Inputs, custom codecs and mutable destinations are caller-owned; a decode failure can leave assignments in place. No context API, transport, cgo or workers are owned.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum TOML document size.

Variables

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

ErrPayloadTooLarge identifies TOML documents over the configured limit.

Functions

func Decode

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

Decode parses one complete TOML document 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 document value and returns owned bytes with codec-sorted map keys. It preserves TOML-specific native values, not a universal cross-format model. The output quota does not bound custom marshaler work or intermediate allocations; 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
	// DisallowUnknownFields rejects Undecoded keys after target decoding, which may already
	// have mutated target.
	DisallowUnknownFields bool
}

DecodeOptions controls TOML decoding and schema strictness.

type EncodeOptions

type EncodeOptions struct {
	// MaxBytes caps returned encoded bytes; zero selects DefaultMaxBytes; negative values fail.
	MaxBytes int64
	// Indent overrides the two-space encoder default using only spaces/tabs; empty keeps that
	// default.
	Indent string
}

EncodeOptions controls TOML serialization. Indent may contain only spaces and tabs; the default is two spaces.

Jump to

Keyboard shortcuts

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