sd_varlink_idl_format, sd_varlink_idl_format_json — Render a Varlink interface definition as text or JSON
#include <systemd/sd-varlink-idl.h>
int sd_varlink_idl_format( | const sd_varlink_interface *interface, |
char **ret); |
int sd_varlink_idl_format_json( | const sd_varlink_interface *interface, |
sd_json_variant **ret); |
sd_varlink_idl_format() renders the specified interface definition, as
built with the SD_VARLINK_DEFINE_INTERFACE() family of macros or parsed with
sd_varlink_idl_parse(), as text in the Varlink interface definition language
(IDL). Documentation comments are rendered along with the definition, and the output is not
colorized and not wrapped, so that it is byte-for-byte reproducible.
sd_varlink_idl_format_json() renders the same definition as a JSON
object. Symbols are grouped by kind, in the same order as in the textual form: enum types,
struct types, methods and errors. Within a group they keep declaration order, and fields keep
declaration order. Call flags are emitted in the canonical order, and the key set is fixed, so
that the output is deterministic as well. The representation carries
the same information as the textual form, including documentation comments and the marking of
experimental interfaces, symbols and fields. It is not yet part of
UAPI.20 Varlink IPC:
the key set below is the interface this function guarantees.
The caller owns the returned text and the returned JSON variant, respectively, and is responsible for freeing them.
The top-level object describes the interface itself:
name"¶The interface name. Always present.
experimental"¶true when the interface is marked experimental. Only
present when the interface is experimental.
comment"¶The documentation comment of the interface. Only present when the definition carries one.
symbols"¶An array of symbol objects, in declaration order. Always present, and empty for an interface without symbols.
Each symbol object describes one method, error or type:
kind"¶One of "method", "error" or
"type". Always present.
name"¶The symbol name. Always present.
experimental", "comment"¶As for the interface, for this symbol.
flags"¶For methods, the call flags that apply, in the canonical order:
"supports-more", "requires-more",
"supports-upgrade" and "requires-upgrade". Only present
when at least one flag applies.
input", "output"¶For methods, the input and output parameters as arrays of field objects. Always present, and empty for a method without parameters.
fields"¶For errors and struct types, the fields as an array of field objects. Always present.
values"¶For enum types, the values as an array of objects with the keys
"name", "experimental" and "comment",
with the same rules as for a symbol. Always present.
typeKind"¶For types, either "struct" or "enum". Always
present on a type.
Each field object carries the field name in "name", and the keys
"experimental" and "comment" with the same rules as above. Its
type is described by exactly one of the following keys:
type"¶A primitive type: "bool", "int",
"float", "string", "object" or
"any".
namedType"¶The name of a type declared in the same interface.
struct", "enum"¶An inline struct, as an array of field objects, or an inline enum, as an array
of objects with "name", "experimental" and
"comment".
nullable", "array", "map"¶true when the field carries the corresponding modifier.
Each key is only present when the modifier applies.
Functions described here are available as a shared
library, which can be compiled against and linked to with the
libsystemd pkg-config(1)
file.
The code described here uses
getenv(3),
which is declared to be not multi-thread-safe. This means that the code calling the functions described
here must not call
setenv(3)
from a parallel thread. It is recommended to only do calls to setenv()
from an early phase of the program when no other threads have been started.
On success, these functions return a non-negative integer. On failure, they return a negative
errno-style error code. In particular, -ENOMEM is returned when memory
allocation fails.
sd_varlink_idl_format() was added in version 257.
sd_varlink_idl_format_json() was added in version 263.