From 7f671b1e68a6664b5baf3e3cffc1bb0880984267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gaul?= Date: Sat, 19 Nov 2016 18:55:49 +0100 Subject: blobmsg: add support for double MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Felix Fietkau --- blobmsg.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'blobmsg.h') diff --git a/blobmsg.h b/blobmsg.h index 861a4e8..7977298 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -31,6 +31,7 @@ enum blobmsg_type { 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, @@ -113,6 +114,18 @@ int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, 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) { @@ -212,6 +225,16 @@ static inline uint64_t blobmsg_get_u64(struct blob_attr *attr) 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) -- cgit v1.2.3