blobmsg: add support for double

This adds support for double floating point type to make it more JSON
compatible. For type checking it also adds a stub BLOB_ATTR_DOUBLE type.
If necessary, the accessor functions for blob can be added later

Signed-off-by: André Gaul <andre@gaul.io>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
André Gaul 2016-11-19 18:55:49 +01:00 committed by Felix Fietkau
parent 0fe13749d0
commit 7f671b1e68
6 changed files with 37 additions and 0 deletions

View file

@ -69,6 +69,9 @@ bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object
case json_type_int:
blobmsg_add_u32(b, name, json_object_get_int(obj));
break;
case json_type_double:
blobmsg_add_double(b, name, json_object_get_double(obj));
break;
case json_type_null:
blobmsg_add_field(b, BLOBMSG_TYPE_UNSPEC, name, NULL, 0);
break;
@ -255,6 +258,9 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo
case BLOBMSG_TYPE_INT64:
sprintf(buf, "%" PRId64, (int64_t) be64_to_cpu(*(uint64_t *)data));
break;
case BLOBMSG_TYPE_DOUBLE:
sprintf(buf, "%lf", blobmsg_get_double(attr));
break;
case BLOBMSG_TYPE_STRING:
blobmsg_format_string(s, data);
return;