WpSpaJson improvements and fixes

Julian Bouzas requested to merge julian/wireplumber:spa-json-improvements into master

This MR improves and fixes a few issues with the current WpSpaJson API:

  • wp_spa_json_build_add_json() now only adds the data represented by size into the builder. This fixes issues when adding nested json objects into a new builder (see commit message for more info). A unit test for that case is also added.
  • wp_spa_json_new_string() now encodes a string in the same way as wp_spa_json_builder_add_string() so that it works with strings that has special characters.
  • A new API called wp_spa_json_to_string() was added. Unlike wp_spa_json_get_data(), the new API always allocates a new string to guarantee its length always matches the WpSpaJson size, regardless of whether the json object is nested or not (see commit message for more info). Maybe we should deprecate wp_spa_json_get_data() in the future? For now I leave it in case someone wants to access the json data quickly without doing an extra allocation.

Merge request reports