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 RejectNonpersistentTag ¶ added in v0.14.0
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.
func ValidateObjects ¶ added in v0.14.0
ValidateObjects checks remainder declarations through a type graph.
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 Object ¶ added in v0.14.0
Object describes the declared names and remainder storage of a Go struct.
type Tag ¶ added in v0.8.0
type Tag struct {
Remain bool
Name string
Skip bool
Omitempty bool
Sensitive bool
AllowNonpersistent bool
Unknown []string
// contains filtered or unexported fields
}
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 ¶ added in v0.8.0
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, sensitive, and allow-nonpersistent 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.
func (Tag) FieldName ¶ added in v0.8.0
FieldName is the map key for a field under the ub tag convention: the tag's name, or the kebab-cased Go field name when the tag names nothing.
func (Tag) ValidateRemain ¶ added in v0.14.0
ValidateRemain checks options on remainder storage.
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.