C Collections

cyaml · Section 3

cyaml_serialize_flow

cyaml_serialize_flow - serialize a DOM tree to flow-style YAML

C Collections (libccollections, -lccollections)

#include <ccollections/cyaml.h>
 
char *cyaml_serialize_flow(cyaml node);

Writes the DOM subtree as compact, flow-style YAML text: A list
becomes [a, b, c], a dictionary becomes {key: value, ...}, and a
scalar follows the same quoting rules as in cyaml_serialize().  The
output is normally one line.
 
Dictionary members come out in insertion order, and a float has a '.'
in its mantissa, exactly as cyaml_serialize(3) describes.
 
Tags follow the same rule as in cyaml_serialize().  A custom tag is
written verbatim as "!<...>" and a core-schema tag is never written,
because a node only ever carries the core-schema tag of its own type.
A byte that the URI characters of YAML 1.2 don't allow literally
inside "!<...>" becomes a percent escape here too, so parsing the tag
again gives the identical string.  See cyaml_serialize(3).
 
Dictionary keys follow the same rule as well.  A key that is exactly
the canonical text of an integer or float key is written without
quotes, and every key that a parse would read as another type or
another text is double-quoted.  A key whose rendered text is longer
than 1024 bytes is written as an explicit "? key: value" entry of the
flow mapping, for the reason that cyaml_serialize(3) gives.  The
decimal point of a float and the locale are handled as there too.
 
The returned string comes from the node's allocator.  Free it with
cyaml_serialize_free() when the tree used the default allocator, and
with cyaml_serialize_free_mp() and that same allocator when it used a
custom one.  cyaml_serialize_free() hands the buffer to plain free(),
and plain free() never allocated a buffer that came from a custom
allocator.
 
node has the same limit of 500 nested containers as in
cyaml_serialize(3),
and this function walks the tree with an explicit worklist instead of
by recursion as well, for the same reason; see the DESCRIPTION of that
page.
 
A NULL node serializes the same way as a CYAML_NULL node ("~").  That
is a successful return with a non-NULL result and does not signal a
failure, and here cyaml_clone(3) differs, because it returns NULL for
a NULL node.

On success, a null-terminated string on the heap.  NULL when the
function runs out of memory or node nests more than 500 containers.

cyaml_dictionary_first(3), cyaml_serialize(3), cyaml_serialize_stream(3), cyaml_serialize_free(3), cyaml_serialize_free_mp(3)