ub

package
v0.6.0-23a Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ub encodes Go values as unobin language literals, the counterpart to encoding/json for unobin's own syntax. Values that implement Marshaler control their own representation; everything else walks reflectively. Marshal emits one-line output; MarshalIndent adds newlines and indentation for nested containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal returns v as a one-line UB expression.

func MarshalIndent

func MarshalIndent(v any, prefix, indent string) ([]byte, error)

MarshalIndent returns v as a multi-line UB expression. prefix is prepended to every line except the first; indent is the per-depth indent string. Atomic values render the same in either form.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal parses data as a UB expression and stores the result in the value pointed to by v. v must be a non-nil pointer. The decode rules mirror the encoder's: bool, integer, float, string, list, map, struct, time.Time, time.Duration, and []byte all decode reflectively. Types implementing Unmarshaler receive the value's UB form (re-rendered from the parsed AST, so callers see a canonical representation rather than the input's original whitespace) at every level: top, struct field, map value, slice element.

Types

type Marshaler

type Marshaler interface {
	MarshalUB() ([]byte, error)
}

Marshaler is implemented by types that supply their own unobin representation. The returned bytes are a single UB expression inserted verbatim into the output; callers control quoting, escaping, and structure.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalUB(data []byte) error
}

Unmarshaler is implemented by types that parse their own unobin representation. UnmarshalUB receives the bytes of the value as they appeared in the input (with surrounding whitespace trimmed by the parser) and populates the receiver.

Jump to

Keyboard shortcuts

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