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 Tag ¶
Tag is a field's parsed ub struct tag. Name is the tag's own name and may be empty; FieldName resolves the kebab-case fallback. Unknown collects options outside the recognized set so the schema reader can warn on a typo such as "sensitiv" instead of quietly accepting it.
func ParseTag ¶
ParseTag reads the value of a ub struct tag: a name, possibly empty, followed by comma-separated options. A value of exactly "-" skips the field. The name and each option are trimmed of spaces; omitempty, squash, and sensitive are the recognized options. Every reader of the tag resolves it through here, so the schema a factory compiles against and the values it encodes and decodes at run time follow one grammar.
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.