std1.0.0-beta-7 SafeC docs

Module serial::value

#include <std/serial/value.h> source

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

ObjectEntryOne key/value pair inside a VAL_OBJECT's obj_val Vec.
Value

Traits

FormatA 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_arrayKept 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_objectkept for std/ml until its refactor moves to the static method
value_stringkept for std/ml until its refactor moves to the static method
value_array_push
value_object_set
value_clone
value_freeDrops *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_NULLValue::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