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 MarshalIndent ¶
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 ¶
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 ¶
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 ¶
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.