Module serial::value
Serializer core: a generic, format-agnostic value tree (Null/Bool/Int/Float/String/Array/Object).
This is the core the format backends (json.sc, xml.sc, html.sc) all build on: each backend only needs 'struct Value -> text' (and, where it makes sense, 'text -> struct Value') — none of them touch a specific struct's fields directly. A struct becomes serializable by writing a 'to_value()' method that builds one of these (see json.h's top comment for a worked example) — SafeC has no field-name/field-type reflection today (only fieldcount(T), a count with no names attached), so this is deliberately a manual, trait-shaped pattern rather than a #[derive]-style automatic one; std/serial/derive.md (n/a here) would be the place to revisit that if reflection ever grows field names.
Ownership: every Value that holds heap data (String, Array, Object) OWNS it — v.free() recursively releases the whole tree, and v.array_push()/v.object_set() take ownership of the Value they're given (don't free it yourself afterward; do call x.clone() first if you still need your own copy).
Structs
| ObjectEntry | One key/value pair inside a VAL_OBJECT's obj_val Vec. |
| Value |
Traits
| Format | A text format for Value trees. Each backend is a small struct whose methods are the format's writer and parser: Json (json.h), Yaml (yaml.h), Csv (csv.h), Xml (xml.h; carries the root element's tag) and Html (html.h). Value::encode / Value::decode take any of them, and so does generic code bounded by Format: |
Functions
| value_array | Kept for std/ml until its refactor moves to the methods above; forward to Value::array() / Value::object() / Value::from_str(s) / arr.array_push(v) / obj.object_set(key, v) / v.clone() / v.free(). |
| value_object | kept for std/ml until its refactor moves to the static method |
| value_string | kept for std/ml until its refactor moves to the static method |
| value_array_push | |
| value_object_set | |
| value_clone | |
| value_free | Drops *v in place: the caller must not use it again (an old-style release through a reference, which the ownership checker can't follow). |
Macros
| VAL_NULL | Value::kind — deliberately plain ints (see collections/map.sc's MapEntry state field for the same convention elsewhere in std) rather than SafeC's tagged-union feature: 'arr_val'/'obj_val' are same-size Vec headers regardless of what they hold, so there's no payload-size mismatch a tagged union would actually save memory on, and this keeps Value a plain flat struct — the simpler, more established shape for something meant to be pushed into Vec elements by raw memcpy. |
| VAL_BOOL | |
| VAL_INT | |
| VAL_FLOAT | |
| VAL_STRING | |
| VAL_ARRAY | |
| VAL_OBJECT |