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
- Variables
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- type DecodeOptions
- type EncodeOptions
Constants ¶
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum TOML document size.
Variables ¶
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.