Spa Json

digraph inheritance { rankdir=LR; GBoxed -> WpSpaJson; GBoxed -> WpSpaJsonBuilder; GBoxed -> WpSpaJsonParser; }

struct WpSpaJson
struct WpSpaJsonBuilder
struct WpSpaJsonParser
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.

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_from_stringn(const gchar *json_str, size_t len)

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

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

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 wether 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 wether 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 wether 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 wether 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 wether 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 wether 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_object(WpSpaJson *self)

Checks wether 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
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
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
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 – the json value

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
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

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.

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
Returns

TRUE if the value was obtained, FALSE otherwise

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.