Documentation
¶
Overview ¶
Package toon implements the Token-Oriented Object Notation (TOON) encoder and decoder described in docs/SPEC.md. TOON is a compact, human-readable serialization format targeting LLM workflows where predictable structure and reduced token counts are important. The package exposes a small public API while keeping implementation details inside internal packages.
Index ¶
- Constants
- func Decode(data []byte, opts ...DecoderOption) (any, error)
- func DecodeString(s string, opts ...DecoderOption) (any, error)
- func Marshal(v any, opts ...EncoderOption) ([]byte, error)
- func MarshalString(v any, opts ...EncoderOption) (string, error)
- func Unmarshal(data []byte, v any, opts ...DecoderOption) error
- func UnmarshalString(s string, v any, opts ...DecoderOption) error
- type Decoder
- type DecoderOption
- type Delimiter
- type Encoder
- type EncoderOption
- type Field
- type Object
Constants ¶
const ( // DelimiterComma is the default delimiter. It is omitted from brackets. DelimiterComma = codec.DelimiterComma // DelimiterTab uses HTAB for delimiting values. DelimiterTab = codec.DelimiterTab // DelimiterPipe uses the '|' character for delimiting values. DelimiterPipe = codec.DelimiterPipe )
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(data []byte, opts ...DecoderOption) (any, error)
Decode parses the provided TOON document using a temporary decoder.
func DecodeString ¶
func DecodeString(s string, opts ...DecoderOption) (any, error)
DecodeString parses a TOON document string using a temporary decoder.
func Marshal ¶
func Marshal(v any, opts ...EncoderOption) ([]byte, error)
Marshal renders v into a TOON document using a temporary encoder.
func MarshalString ¶
func MarshalString(v any, opts ...EncoderOption) (string, error)
MarshalString renders v as a TOON document string.
func Unmarshal ¶
func Unmarshal(data []byte, v any, opts ...DecoderOption) error
Unmarshal decodes the TOON document in data into v, which must be a non-nil pointer. Struct fields use `toon` struct tags for naming and omitempty semantics, mirroring Marshal behaviour.
func UnmarshalString ¶
func UnmarshalString(s string, v any, opts ...DecoderOption) error
UnmarshalString decodes the TOON document in s into v.
Types ¶
type Decoder ¶
Decoder parses TOON documents into Go values that match the data model from Section 2. Numbers are returned as float64, objects as map[string]any, and arrays as []any. Strings are unescaped per Section 7.1.
func NewDecoder ¶
func NewDecoder(opts ...DecoderOption) *Decoder
NewDecoder constructs a Decoder with the given options.
type DecoderOption ¶
type DecoderOption = codec.DecoderOption
DecoderOption mutates decoder behaviour.
func WithDecoderDocumentDelimiter ¶
func WithDecoderDocumentDelimiter(delimiter Delimiter) DecoderOption
WithDecoderDocumentDelimiter configures the delimiter that influences delimiter-aware string parsing when no array header is active.
func WithDecoderIndent ¶
func WithDecoderIndent(spaces int) DecoderOption
WithDecoderIndent configures the expected indentation step.
func WithStrictMode ¶
func WithStrictMode(strict bool) DecoderOption
WithStrictMode toggles the strict-mode diagnostics.
type Encoder ¶
Encoder serializes Go values as TOON documents.
func NewEncoder ¶
func NewEncoder(opts ...EncoderOption) *Encoder
NewEncoder constructs an Encoder using the supplied options. Absent options default to the TOON Core Profile recommendations (Section 19).
type EncoderOption ¶
type EncoderOption = codec.EncoderOption
EncoderOption mutates encoding behaviour.
func WithArrayDelimiter ¶
func WithArrayDelimiter(delimiter Delimiter) EncoderOption
WithArrayDelimiter configures the default delimiter declared for arrays that do not explicitly override the active delimiter.
func WithDocumentDelimiter ¶
func WithDocumentDelimiter(delimiter Delimiter) EncoderOption
WithDocumentDelimiter configures the delimiter that influences quoting decisions outside array scopes.
func WithIndent ¶
func WithIndent(spaces int) EncoderOption
WithIndent configures the number of spaces used per indentation level.
func WithLengthMarkers ¶
func WithLengthMarkers(enabled bool) EncoderOption
WithLengthMarkers enables emitting optional # markers in array headers.
func WithTimeFormatter ¶
func WithTimeFormatter(formatter func(time.Time) string) EncoderOption
WithTimeFormatter specifies the formatter used for time.Time normalization.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
delimiters
command
|
|
|
mixedarrays
command
|
|
|
normalize
command
|
|
|
strictmode
command
|
|
|
internal
|
|