[BLOB_ATTR_INT16] = sizeof(uint16_t),
[BLOB_ATTR_INT32] = sizeof(uint32_t),
[BLOB_ATTR_INT64] = sizeof(uint64_t),
+ [BLOB_ATTR_DOUBLE] = sizeof(double),
};
bool
BLOB_ATTR_INT16,
BLOB_ATTR_INT32,
BLOB_ATTR_INT64,
+ BLOB_ATTR_DOUBLE,
BLOB_ATTR_LAST
};
[BLOBMSG_TYPE_INT16] = BLOB_ATTR_INT16,
[BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32,
[BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64,
+ [BLOBMSG_TYPE_DOUBLE] = BLOB_ATTR_DOUBLE,
[BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
[BLOBMSG_TYPE_UNSPEC] = BLOB_ATTR_BINARY,
};
BLOBMSG_TYPE_INT32,
BLOBMSG_TYPE_INT16,
BLOBMSG_TYPE_INT8,
+ BLOBMSG_TYPE_DOUBLE,
__BLOBMSG_TYPE_LAST,
BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1,
BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8,
int blobmsg_add_field(struct blob_buf *buf, int type, const char *name,
const void *data, unsigned int len);
+static inline int
+blobmsg_add_double(struct blob_buf *buf, const char *name, double val)
+{
+ union {
+ double d;
+ uint64_t u64;
+ } v;
+ v.d = val;
+ v.u64 = cpu_to_be64(v.u64);
+ return blobmsg_add_field(buf, BLOBMSG_TYPE_DOUBLE, name, &v.u64, 8);
+}
+
static inline int
blobmsg_add_u8(struct blob_buf *buf, const char *name, uint8_t val)
{
return tmp;
}
+static inline double blobmsg_get_double(struct blob_attr *attr)
+{
+ union {
+ double d;
+ uint64_t u64;
+ } v;
+ v.u64 = blobmsg_get_u64(attr);
+ return v.d;
+}
+
static inline char *blobmsg_get_string(struct blob_attr *attr)
{
if (!attr)
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;
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;
case BLOBMSG_TYPE_INT64:
indent_printf(indent, "%"PRIu64"\n", blobmsg_get_u64(data));
break;
+ case BLOBMSG_TYPE_DOUBLE:
+ indent_printf(indent, "%lf\n", blobmsg_get_double(data));
+ break;
case BLOBMSG_TYPE_TABLE:
case BLOBMSG_TYPE_ARRAY:
if (!indent)
blobmsg_add_string(buf, "message", "Hello, world!");
tbl = blobmsg_open_table(buf, "testdata");
+ blobmsg_add_double(buf, "double", 1.337e2);
blobmsg_add_u32(buf, "hello", 1);
blobmsg_add_string(buf, "world", "2");
blobmsg_close_table(buf, tbl);
blobmsg_add_u32(buf, NULL, 0);
blobmsg_add_u32(buf, NULL, 1);
blobmsg_add_u32(buf, NULL, 2);
+ blobmsg_add_double(buf, "double", 1.337e2);
blobmsg_close_table(buf, tbl);
}