mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
u/u_json: Implement u_json_get_int_array()
This commit is contained in:
parent
ce13de9484
commit
f8a486884b
|
@ -328,6 +328,39 @@ u_json_get_double_array(const cJSON *json_array, double *out_array, size_t max_s
|
|||
return i;
|
||||
}
|
||||
|
||||
size_t
|
||||
u_json_get_int_array(const cJSON *json_array, int *out_array, size_t max_size)
|
||||
{
|
||||
assert(out_array != NULL);
|
||||
|
||||
if (!json_array) {
|
||||
return 0;
|
||||
}
|
||||
if (!cJSON_IsArray(json_array)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
const cJSON *elt;
|
||||
cJSON_ArrayForEach(elt, json_array)
|
||||
{
|
||||
if (i >= max_size) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!u_json_get_int(elt, &out_array[i])) {
|
||||
U_LOG_W(
|
||||
"u_json_get_int got a non-number in a "
|
||||
"numeric array");
|
||||
return i;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
bool
|
||||
u_json_get_matrix_3x3(const cJSON *json, struct xrt_matrix_3x3 *out_matrix)
|
||||
{
|
||||
|
|
|
@ -117,6 +117,14 @@ u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_siz
|
|||
size_t
|
||||
u_json_get_double_array(const cJSON *json_array, double *out_array, size_t max_size);
|
||||
|
||||
/*!
|
||||
* @brief Parse up to max_size int from a JSON array.
|
||||
*
|
||||
* @return the number of elements set.
|
||||
*/
|
||||
size_t
|
||||
u_json_get_int_array(const cJSON *json_array, int *out_array, size_t max_size);
|
||||
|
||||
/*!
|
||||
* @brief Parse a matrix_3x3 from a JSON object.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue