Spa Json — WirePlumber 0.5.17 documentation

# Spa Json

struct WpSpaJson

  Since

    0.4.8

struct WpSpaJsonBuilder

  Since

    0.4.8

struct WpSpaJsonParser

  Since

    0.4.8

WpSpaJson *wp_spa_json_ref(WpSpaJson *self)

  Increases the reference count of a spa json object.

  Parameters:

    - self -- a spa json object

  Returns:

    (transfer full): self with an additional reference count on it

void wp_spa_json_unref(WpSpaJson *self)

  Decreases the reference count on self and frees it when the ref count reaches zero.

  Parameters:

    - self -- (transfer full): a spa json object

WpSpaJson *wp_spa_json_new_from_string(const gchar *json_str)

  Constructs a new WpSpaJson from a JSON string.

  Since

    0.5.0

  Parameters:

    - json_str -- a JSON string

  Returns:

    a new WpSpaJson; unlike the "wrap" variants, this function copies the data in json_str, so it does not need to stay alive.

WpSpaJson *wp_spa_json_new_from_stringn(const gchar *json_str, size_t len)

  Constructs a new WpSpaJson from a JSON string with specific length.

  Since

    0.5.0

  Parameters:

    - json_str -- a JSON string

    - len -- the specific length of the string

  Returns:

    a new WpSpaJson; unlike the "wrap" variants, this function copies the data in json_str, so it does not need to stay alive.

WpSpaJson *wp_spa_json_new_wrap_string(const gchar *json_str)

  Constructs a new WpSpaJson that wraps a JSON string.

  Since

    0.5.0

  Parameters:

    - json_str -- a JSON string

  Returns:

    a new WpSpaJson that references the data in json_str. json_str is not copied, so it needs to stay alive.

WpSpaJson *wp_spa_json_new_wrap_stringn(const gchar *json_str, size_t len)

  Constructs a new WpSpaJson that wraps a JSON string with specific length.

  Since

    0.5.0

  Parameters:

    - json_str -- a JSON string

    - len -- the specific length of the string

  Returns:

    a new WpSpaJson that references the data in json_str. json_str is not copied, so it needs to stay alive.

WpSpaJson *wp_spa_json_new_wrap(struct spa_json *json)

  Constructs a new WpSpaJson that wraps the given `spa_json`.

  Parameters:

    - json -- a spa_json

  Returns:

    a new WpSpaJson that references the data in json. json is not copied, so it needs to stay alive.

const struct spa_json *wp_spa_json_get_spa_json(const WpSpaJson *self)

  Converts a WpSpaJson pointer to a `struct spa_json` one, for use with native pipewire & spa functions. The returned pointer is owned by WpSpaJson and may not be modified or freed.

  Parameters:

    - self -- a spa json object

  Returns:

    a const pointer to the underlying spa_json structure

const gchar *wp_spa_json_get_data(const WpSpaJson *self)

  Returns the json data.

  Parameters:

    - self -- a spa json object

  Returns:

    a const pointer to the json data

size_t wp_spa_json_get_size(const WpSpaJson *self)

  Returns the json data size.

  Parameters:

    - self -- a spa json object

  Returns:

    the json data size

gchar *wp_spa_json_to_string(const WpSpaJson *self)

  Returns a newly allocated json string with length matching the size.

  Since

    0.4.11

  Parameters:

    - self -- a spa json object

  Returns:

    (transfer full): the json string with length matching the size

WpSpaJson *wp_spa_json_copy(WpSpaJson *other)

  Copies a spa json object.

  Parameters:

    - other -- a spa json object

  Returns:

    (transfer full): The newly copied spa json

gboolean wp_spa_json_is_unique_owner(WpSpaJson *self)

  Checks if the json is the unique owner of its data or not.

  Parameters:

    - self -- a spa json object

  Returns:

    TRUE if the json owns the data, FALSE otherwise.

WpSpaJson *wp_spa_json_ensure_unique_owner(WpSpaJson *self)

  If self is not uniquely owned already, then it is unrefed and a copy of it is returned instead. You should always consider self as unsafe to use after this call and you should use the returned object instead.

  Parameters:

    - self -- (transfer full): a spa json object

  Returns:

    (transfer full): the uniquely owned spa json object which may or may not be the same as self.

WpSpaJson *wp_spa_json_new_null(void)

  Creates a spa json of type NULL.

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_boolean(gboolean value)

  Creates a spa json of type boolean.

  Parameters:

    - value -- the boolean value

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_int(gint value)

  Creates a spa json of type int.

  Parameters:

    - value -- the int value

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_float(float value)

  Creates a spa json of type float.

  Parameters:

    - value -- the float value

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_string(const gchar *value)

  Creates a spa json of type string.

  Parameters:

    - value -- the string value

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_array(const gchar *format, ...)

  Creates a spa json of type array.

  Parameters:

    - format -- (nullable): the first value format ("n", "b", "i", "f", "s" or "J")

    - ... -- a list of array types and values, followed by NULL

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_array_valist(const gchar *format, va_list args)

  This is the `va_list` version of wp_spa_json_new_array().

  Parameters:

    - format -- (nullable): the first value format ("n", "b", "i", "f", "s" or "J")

    - args -- the variable arguments passed to wp_spa_json_new_array()

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_object(const gchar *key, const gchar *format, ...)

  Creates a spa json of type object.

  Parameters:

    - key -- (nullable): the first object property key

    - format -- (nullable): the first property format ("n", "b", "i", "f", "s" or "J")

    - ... -- a list of object properties and values, followed by NULL

  Returns:

    (transfer full): The new spa json

WpSpaJson *wp_spa_json_new_object_valist(const gchar *key, const gchar *format, va_list args)

  This is the `va_list` version of wp_spa_json_new_object().

  Parameters:

    - key -- (nullable): the first object property key

    - format -- (nullable): the first property format ("n", "b", "i", "f", "s" or "J")

    - args -- the variable arguments passed to wp_spa_json_new_object()

  Returns:

    (transfer full): The new spa json

gboolean wp_spa_json_is_null(WpSpaJson *self)

  Checks whether the spa json is of type null or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type null, FALSE otherwise

gboolean wp_spa_json_is_boolean(WpSpaJson *self)

  Checks whether the spa json is of type boolean or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type boolean, FALSE otherwise

gboolean wp_spa_json_is_int(WpSpaJson *self)

  Checks whether the spa json is of type int or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type int, FALSE otherwise

gboolean wp_spa_json_is_float(WpSpaJson *self)

  Checks whether the spa json is of type float or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type float, FALSE otherwise

gboolean wp_spa_json_is_string(WpSpaJson *self)

  Checks whether the spa json is of type string or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type string, FALSE otherwise

gboolean wp_spa_json_is_array(WpSpaJson *self)

  Checks whether the spa json is of type array or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type array, FALSE otherwise

gboolean wp_spa_json_is_container(WpSpaJson *self)

  Checks whether the spa json is of type container or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type container, FALSE otherwise

gboolean wp_spa_json_is_object(WpSpaJson *self)

  Checks whether the spa json is of type object or not.

  Parameters:

    - self -- the spa json object

  Returns:

    TRUE if it is of type object, FALSE otherwise

gboolean wp_spa_json_parse_boolean(WpSpaJson *self, gboolean *value)

  Parses the boolean value of a spa json object.

  Parameters:

    - self -- the spa json object

    - value -- (out): the boolean value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gboolean wp_spa_json_parse_int(WpSpaJson *self, gint *value)

  Parses the int value of a spa json object.

  Parameters:

    - self -- the spa json object

    - value -- (out): the int value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gboolean wp_spa_json_parse_float(WpSpaJson *self, float *value)

  Parses the float value of a spa json object.

  Parameters:

    - self -- the spa json object

    - value -- (out): the float value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gchar *wp_spa_json_parse_string(WpSpaJson *self)

  Parses the string value of a spa json object.

  Parameters:

    - self -- the spa json object

  Returns:

    (transfer full): The newly allocated parsed string

gboolean wp_spa_json_parse_array(WpSpaJson *self, ...)

  Parses the array types and values of a spa json object.

  Parameters:

    - self -- the spa json object

    - ... -- (out): the list of array types and values, followed by NULL

  Returns:

    TRUE if the types and values were obtained, FALSE otherwise

gboolean wp_spa_json_parse_array_valist(WpSpaJson *self, va_list args)

  This is the `va_list` version of wp_spa_json_parse_array().

  Parameters:

    - self -- the spa json object

    - args -- (out): the variable arguments passed to wp_spa_json_parse_array()

  Returns:

    TRUE if the types and values were obtained, FALSE otherwise

gboolean wp_spa_json_parse_object(WpSpaJson *self, ...)

  Parses the object properties and values of a spa json object.

  Parameters:

    - self -- the spa json object

    - ... -- (out): the list of object properties and values, followed by NULL

  Returns:

    TRUE if the properties and values were obtained, FALSE otherwise

gboolean wp_spa_json_parse_object_valist(WpSpaJson *self, va_list args)

  This is the `va_list` version of wp_spa_json_parse_object().

  Parameters:

    - self -- the spa json object

    - args -- (out): the variable arguments passed to wp_spa_json_parse_object()

  Returns:

    TRUE if the properties and values were obtained, FALSE otherwise

gboolean wp_spa_json_object_get(WpSpaJson *self, ...)

  Parses the object property values of a spa json object.

  Parameters:

    - self -- the spa json object

    - ... -- the list of property names, formats and values, followed by NULL

  Returns:

    TRUE if the properties and values were obtained, FALSE otherwise

gboolean wp_spa_json_object_get_valist(WpSpaJson *self, va_list args)

  This is the `va_list` version of wp_spa_json_object_get().

  Parameters:

    - self -- the spa json object

    - args -- the variable arguments passed to wp_spa_json_object_get()

  Returns:

    TRUE if the properties and values were obtained, FALSE otherwise

WpSpaJsonBuilder *wp_spa_json_builder_ref(WpSpaJsonBuilder *self)

  Increases the reference count of a spa json builder.

  Parameters:

    - self -- a spa json builder object

  Returns:

    (transfer full): self with an additional reference count on it

void wp_spa_json_builder_unref(WpSpaJsonBuilder *self)

  Decreases the reference count on self and frees it when the ref count reaches zero.

  Parameters:

    - self -- (transfer full): a spa json builder object

WpSpaJsonBuilder *wp_spa_json_builder_new_array(void)

  Creates a spa json builder of type array.

  Returns:

    (transfer full): the new spa json builder

WpSpaJsonBuilder *wp_spa_json_builder_new_object(void)

  Creates a spa json builder of type object.

  Returns:

    (transfer full): the new spa json builder

void wp_spa_json_builder_add_property(WpSpaJsonBuilder *self, const gchar *key)

  Adds a property into the builder.

  Parameters:

    - self -- the spa json builder object

    - key -- the name of the property

void wp_spa_json_builder_add_null(WpSpaJsonBuilder *self)

  Adds a null value into the builder.

  Parameters:

    - self -- the spa json builder object

void wp_spa_json_builder_add_boolean(WpSpaJsonBuilder *self, gboolean value)

  Adds a boolean value into the builder.

  Parameters:

    - self -- the spa json builder object

    - value -- the boolean value

void wp_spa_json_builder_add_int(WpSpaJsonBuilder *self, gint value)

  Adds a int value into the builder.

  Parameters:

    - self -- the spa json builder object

    - value -- the int value

void wp_spa_json_builder_add_float(WpSpaJsonBuilder *self, float value)

  Adds a float value into the builder.

  Parameters:

    - self -- the spa json builder object

    - value -- the float value

void wp_spa_json_builder_add_string(WpSpaJsonBuilder *self, const gchar *value)

  Adds a string value into the builder.

  Parameters:

    - self -- the spa json builder object

    - value -- the string value

void wp_spa_json_builder_add_json(WpSpaJsonBuilder *self, WpSpaJson *json)

  Adds a json value into the builder.

  Parameters:

    - self -- the spa json builder object

    - json -- (transfer none): the json value

void wp_spa_json_builder_add_from_string(WpSpaJsonBuilder *self, const gchar *json_str)

  Adds a json string into the builder.

  Parameters:

    - self -- the spa json builder object

    - json_str -- the json string

void wp_spa_json_builder_add_from_stringn(WpSpaJsonBuilder *self, const gchar *json_str, size_t len)

  Adds a json string with specific length into the builder.

  Parameters:

    - self -- the spa json builder object

    - json_str -- the json string

    - len -- the specific length of the json string

void wp_spa_json_builder_add(WpSpaJsonBuilder *self, ...)

  Adds values into the builder.

  Parameters:

    - self -- the spa json builder object

    - ... -- the json values

void wp_spa_json_builder_add_valist(WpSpaJsonBuilder *self, va_list args)

  This is the `va_list` version of wp_spa_json_builder_add().

  Parameters:

    - self -- the spa json builder object

    - args -- the variable arguments passed to wp_spa_json_builder_add()

WpSpaJson *wp_spa_json_builder_end(WpSpaJsonBuilder *self)

  Ends the builder process and returns the constructed spa json object.

  Parameters:

    - self -- the spa json builder object

  Returns:

    (transfer full): the constructed spa json object

WpSpaJsonParser *wp_spa_json_parser_ref(WpSpaJsonParser *self)

  Increases the reference count of a spa json parser.

  Parameters:

    - self -- a spa json parser object

  Returns:

    (transfer full): self with an additional reference count on it

void wp_spa_json_parser_unref(WpSpaJsonParser *self)

  Decreases the reference count on self and frees it when the ref count reaches zero.

  Parameters:

    - self -- (transfer full): a spa json parser object

WpSpaJsonParser *wp_spa_json_parser_new_array(WpSpaJson *json)

  Creates a spa json array parser. The json object must be valid for the entire life-cycle of the returned parser.

  Parameters:

    - json -- the spa json array to parse

  Returns:

    (transfer full): The new spa json parser

WpSpaJsonParser *wp_spa_json_parser_new_object(WpSpaJson *json)

  Creates a spa json object parser. The json object must be valid for the entire life-cycle of the returned parser.

  Parameters:

    - json -- the spa json object to parse

  Returns:

    (transfer full): The new spa json parser

WpSpaJsonParser *wp_spa_json_parser_new_undefined(WpSpaJson *json)

  Creates a new spa json parser for undefined type of data. The json object must be valid for the entire life-cycle of the returned parser.

  This function allows creating a parser object for any type of spa json and is mostly useful to parse non-standard JSON data that should be treated as if it were an object or array, but does not start with a '{' or '[' character. Such data can be for instance a comma-separated list of single values (array) or key-value pairs (object). Such data is also the main configuration file, which is an object but doesn't start with a '{' character.

  Since

    0.5.0

  Note

  If the data is an array or object, the parser will not enter it and the only token it will be able to parse is the same json object that is passed in as an argument. Use wp_spa_json_parser_new_array() or wp_spa_json_parser_new_object() to parse arrays or objects.

  Parameters:

    - json -- the spa json to parse

  Returns:

    (transfer full): The new spa json parser

gboolean wp_spa_json_parser_get_null(WpSpaJsonParser *self)

  Gets the null value from a spa json parser.

  Parameters:

    - self -- the spa json parser object

  Returns:

    TRUE if the null value is present, FALSE otherwise

gboolean wp_spa_json_parser_get_boolean(WpSpaJsonParser *self, gboolean *value)

  Gets the boolean value from a spa json parser.

  Parameters:

    - self -- the spa json parser object

    - value -- (out): the boolean value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gboolean wp_spa_json_parser_get_int(WpSpaJsonParser *self, gint *value)

  Gets the int value from a spa json parser object.

  Parameters:

    - self -- the spa json parser object

    - value -- (out): the int value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gboolean wp_spa_json_parser_get_float(WpSpaJsonParser *self, float *value)

  Gets the float value from a spa json parser object.

  Parameters:

    - self -- the spa json parser object

    - value -- (out): the float value

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gchar *wp_spa_json_parser_get_string(WpSpaJsonParser *self)

  Gets the string value from a spa json parser object.

  Parameters:

    - self -- the spa json parser object

  Returns:

    (transfer full): The newly allocated parsed string

WpSpaJson *wp_spa_json_parser_get_json(WpSpaJsonParser *self)

  Gets the spa json value from a spa json parser object.

  Note

  the returned spa json object references the original data instead of copying it, therefore the original data must be valid for the entire life-cycle of the returned object

  Parameters:

    - self -- the spa json parser object

  Returns:

    (transfer full): The spa json value or NULL if it could not be obtained

gboolean wp_spa_json_parser_get(WpSpaJsonParser *self, ...)

  Gets the values from a spa json parser object.

  Parameters:

    - self -- the spa json parser object

    - ... -- (out): a list of values to get, followed by NULL

  Returns:

    TRUE if the value was obtained, FALSE otherwise

gboolean wp_spa_json_parser_get_valist(WpSpaJsonParser *self, va_list args)

  This is the `va_list` version of wp_spa_json_parser_get().

  Parameters:

    - self -- the spa json parser object

    - args -- the variable arguments passed to wp_spa_json_parser_get()

  Returns:

    TRUE if the value was obtained, FALSE otherwise

void wp_spa_json_parser_end(WpSpaJsonParser *self)

  Ends the parsing session.

  After this is called, no more tokens can be parsed with self.

  Parameters:

    - self -- the spa json parser

WpIterator *wp_spa_json_new_iterator(WpSpaJson *self)

  Creates a new iterator for a spa json object.

  Parameters:

    - self -- the spa json object

  Returns:

    (transfer full): the new spa json iterator

WP_TYPE_SPA_JSON (wp_spa_json_get_type ())

  The WpSpaJson GType.

WP_TYPE_SPA_JSON_BUILDER (wp_spa_json_builder_get_type ())

  The WpSpaJsonBuilder GType.

WP_TYPE_SPA_JSON_PARSER (wp_spa_json_parser_get_type ())

  The WpSpaJsonParser GType.