Error when parsing numbers of different types
I just run into a problem when parsing json of the form
{
kind: 5
}
I used
guint kind = 0;
JSONRPC_MESSAGE_PARSE(node, "kind", JSONRPC_MESSAGE_GET_INT32(&kind));
and parsing ended with error - it only worked when I switched to 64bit integers and JSONRPC_MESSAGE_GET_INT64
.
The problem is that the internal representation of GVariant may not correspond to expectations of the developer using this API. The number 5
above may even be a double, just written without the decimal part in an array of other doubles that have the decimal part and will be represented as doubles using GVariant. In my opinion the part here:
https://gitlab.gnome.org/GNOME/jsonrpc-glib/-/blob/main/src/jsonrpc-message.c?ref_type=heads#L477
shouldn't be based on the type of valptr
but instead, in principle, something like
else if (IS_GET_INT32 (valptr) || IS_GET_INT64 (valptr) || IS_GET_DOUBLE (valptr))
ret = g_variant_dict_lookup (dict, key, "i", &val32);
if (ret)
//assign val32 to valptr
if (!ret)
ret = g_variant_dict_lookup (dict, key, "x", &val64);
if (ret)
//assign val64 to valptr
if (!ret)
ret = g_variant_dict_lookup (dict, key, "d", &val_double);
if (ret)
//assign val_32_double to valptr
Of course it would be the developer's responsibility to provide big enough value so e.g. 64-bit integers don't get truncated to 32-bit integers.
Or is the way the API works right now intentional and I'm missing something?