From 9b6cb9ddd33078a255871d0b3605eff82424ce45 Mon Sep 17 00:00:00 2001 From: Bastien BERNARD Date: Mon, 20 Apr 2026 11:00:50 +0200 Subject: [PATCH] libubox: add boolean type support Create a distinguished BLOBMSG_TYPE_BOOL in order to differenciate int8 and boolean types (both still use BLOB_ATTR_INT8 as storage format). Signed-off-by: Bastien BERNARD --- blobmsg.c | 1 + blobmsg.h | 11 ++++- blobmsg_json.c | 5 ++- tests/cram/test_blobmsg.t | 72 ++++++++++++++++----------------- tests/cram/test_blobmsg_types.t | 26 ++++++++---- tests/fuzz/test-fuzz.c | 1 + tests/test-blobmsg-types.c | 56 ++++++++++++++++++++++--- 7 files changed, 121 insertions(+), 51 deletions(-) diff --git a/blobmsg.c b/blobmsg.c index fdf3337..cbe5f42 100644 --- a/blobmsg.c +++ b/blobmsg.c @@ -19,6 +19,7 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = { [BLOBMSG_TYPE_INT8] = BLOB_ATTR_INT8, + [BLOBMSG_TYPE_BOOL] = BLOB_ATTR_INT8, [BLOBMSG_TYPE_INT16] = BLOB_ATTR_INT16, [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32, [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64, diff --git a/blobmsg.h b/blobmsg.h index b79e7e6..fec45cf 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -31,7 +31,7 @@ enum blobmsg_type { BLOBMSG_TYPE_INT32, BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, - BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, + BLOBMSG_TYPE_BOOL, BLOBMSG_TYPE_DOUBLE, __BLOBMSG_TYPE_LAST, BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1, @@ -231,6 +231,13 @@ blobmsg_add_u64(struct blob_buf *buf, const char *name, uint64_t val) return blobmsg_add_field(buf, BLOBMSG_TYPE_INT64, name, &val, 8); } +static inline int +blobmsg_add_bool(struct blob_buf *buf, const char *name, bool val) +{ + uint8_t v = val ? 1 : 0; + return blobmsg_add_field(buf, BLOBMSG_TYPE_BOOL, name, &v, 1); +} + static inline int blobmsg_add_string(struct blob_buf *buf, const char *name, const char *string) { @@ -319,6 +326,7 @@ static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr) tmp = blobmsg_get_u16(attr); break; case BLOBMSG_TYPE_INT8: + case BLOBMSG_TYPE_BOOL: tmp = blobmsg_get_u8(attr); break; default: @@ -345,6 +353,7 @@ static inline int64_t blobmsg_cast_s64(struct blob_attr *attr) tmp = (int16_t) blobmsg_get_u16(attr); break; case BLOBMSG_TYPE_INT8: + case BLOBMSG_TYPE_BOOL: tmp = (int8_t) blobmsg_get_u8(attr); break; default: diff --git a/blobmsg_json.c b/blobmsg_json.c index 4865cd3..78123be 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -60,7 +60,7 @@ bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object blobmsg_add_string(b, name, json_object_get_string(obj)); break; case json_type_boolean: - blobmsg_add_u8(b, name, json_object_get_boolean(obj)); + blobmsg_add_bool(b, name, json_object_get_boolean(obj)); break; case json_type_int: { int64_t i64 = json_object_get_int64(obj); @@ -262,6 +262,9 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo case BLOBMSG_TYPE_BOOL: snprintf(buf, sizeof(buf), "%s", *(uint8_t *)data ? "true" : "false"); break; + case BLOBMSG_TYPE_INT8: + snprintf(buf, sizeof(buf), "%" PRId8, *(int8_t *)data); + break; case BLOBMSG_TYPE_INT16: snprintf(buf, sizeof(buf), "%" PRId16, (int16_t) be16_to_cpu(*(uint16_t *)data)); break; diff --git a/tests/cram/test_blobmsg.t b/tests/cram/test_blobmsg.t index 67a9d80..08c2aa2 100644 --- a/tests/cram/test_blobmsg.t +++ b/tests/cram/test_blobmsg.t @@ -35,15 +35,15 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":0,"poo":100,"moo-min":-128,"moo-max":127,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[0,100,-128,127,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} [*] blobmsg from json: Message: Hello, world! List: { - 0 (i8) - 1 (i8) - 1 (i8) - 1 (i8) + 0 (i32) + 100 (i32) + -128 (i32) + 127 (i32) -32768 (i32) 32767 (i32) -2147483648 (i32) @@ -56,10 +56,10 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) + \tfoo : 0 (i32) (esc) + \tpoo : 100 (i32) (esc) + \tmoo-min : -128 (i32) (esc) + \tmoo-max : 127 (i32) (esc) \tbar-min : -32768 (i32) (esc) \tbar-max : 32767 (i32) (esc) \tbaz-min : -2147483648 (i32) (esc) @@ -102,15 +102,15 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":0,"poo":100,"moo-min":-128,"moo-max":127,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[0,100,-128,127,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} [*] blobmsg from json: Message: Hello, world! List: { - 0 (i8) - 1 (i8) - 1 (i8) - 1 (i8) + 0 (i32) + 100 (i32) + -128 (i32) + 127 (i32) -32768 (i32) 32767 (i32) -2147483648 (i32) @@ -123,10 +123,10 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) + \tfoo : 0 (i32) (esc) + \tpoo : 100 (i32) (esc) + \tmoo-min : -128 (i32) (esc) + \tmoo-max : 127 (i32) (esc) \tbar-min : -32768 (i32) (esc) \tbar-max : 32767 (i32) (esc) \tbaz-min : -2147483648 (i32) (esc) @@ -169,15 +169,15 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":0,"poo":100,"moo-min":-128,"moo-max":127,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[0,100,-128,127,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} [*] blobmsg from json: Message: Hello, world! List: { - 0 (i8) - 1 (i8) - 1 (i8) - 1 (i8) + 0 (i32) + 100 (i32) + -128 (i32) + 127 (i32) -32768 (i32) 32767 (i32) -2147483648 (i32) @@ -190,10 +190,10 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) + \tfoo : 0 (i32) (esc) + \tpoo : 100 (i32) (esc) + \tmoo-min : -128 (i32) (esc) + \tmoo-max : 127 (i32) (esc) \tbar-min : -32768 (i32) (esc) \tbar-max : 32767 (i32) (esc) \tbaz-min : -2147483648 (i32) (esc) @@ -236,15 +236,15 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":2.2250738585072014e-308,"dbl-max":1.7976931348623157e+308,"foo":0,"poo":100,"moo-min":-128,"moo-max":127,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[0,100,-128,127,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,2.2250738585072014e-308,1.7976931348623157e+308]} [*] blobmsg from json: Message: Hello, world! List: { - 0 (i8) - 1 (i8) - 1 (i8) - 1 (i8) + 0 (i32) + 100 (i32) + -128 (i32) + 127 (i32) -32768 (i32) 32767 (i32) -2147483648 (i32) @@ -257,10 +257,10 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) + \tfoo : 0 (i32) (esc) + \tpoo : 100 (i32) (esc) + \tmoo-min : -128 (i32) (esc) + \tmoo-max : 127 (i32) (esc) \tbar-min : -32768 (i32) (esc) \tbar-max : 32767 (i32) (esc) \tbaz-min : -2147483648 (i32) (esc) diff --git a/tests/cram/test_blobmsg_types.t b/tests/cram/test_blobmsg_types.t index 4def0e6..b914d9c 100644 --- a/tests/cram/test_blobmsg_types.t +++ b/tests/cram/test_blobmsg_types.t @@ -15,6 +15,8 @@ check that blobmsg is producing expected results: int8_min: -128 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: true + bool_false: false [*] blobmsg dump cast_u64: string: Hello, world! int64_max: 9223372036854775807 @@ -27,6 +29,8 @@ check that blobmsg is producing expected results: int8_min: 128 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: 1 + bool_false: 0 [*] blobmsg dump cast_s64: string: Hello, world! int64_max: 9223372036854775807 @@ -39,8 +43,10 @@ check that blobmsg is producing expected results: int8_min: -128 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: 1 + bool_false: 0 - [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"int16_max":32767,"int16_min":-32768,"int8_max":true,"int8_min":true,"double_max":1.7976931348623157e+308,"double_min":2.2250738585072014e-308} + [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"int16_max":32767,"int16_min":-32768,"int8_max":127,"int8_min":-128,"double_max":1.7976931348623157e+308,"double_min":2.2250738585072014e-308,"bool_true":true,"bool_false":false} [*] blobmsg from json: string: Hello, world! @@ -50,10 +56,12 @@ check that blobmsg is producing expected results: int32_min: -2147483648 int16_max: 32767 int16_min: -32768 - int8_max: 1 - int8_min: 1 + int8_max: 127 + int8_min: -128 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: true + bool_false: false [*] blobmsg from json/cast_u64: string: Hello, world! @@ -63,10 +71,12 @@ check that blobmsg is producing expected results: int32_min: 2147483648 int16_max: 32767 int16_min: 4294934528 - int8_max: 1 - int8_min: 1 + int8_max: 127 + int8_min: 4294967168 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: 1 + bool_false: 0 [*] blobmsg from json/cast_s64: string: Hello, world! @@ -76,7 +86,9 @@ check that blobmsg is producing expected results: int32_min: -2147483648 int16_max: 32767 int16_min: -32768 - int8_max: 1 - int8_min: 1 + int8_max: 127 + int8_min: -128 double_max: 1.797693e+308 double_min: 2.225074e-308 + bool_true: 1 + bool_false: 0 diff --git a/tests/fuzz/test-fuzz.c b/tests/fuzz/test-fuzz.c index 026a3fd..3aa34f2 100644 --- a/tests/fuzz/test-fuzz.c +++ b/tests/fuzz/test-fuzz.c @@ -26,6 +26,7 @@ static void fuzz_blobmsg_parse(const uint8_t *data, size_t size) BLOBMSG_TYPE_INT32, BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, + BLOBMSG_TYPE_BOOL, BLOBMSG_TYPE_DOUBLE, BLOBMSG_TYPE_TROUBLE, }; diff --git a/tests/test-blobmsg-types.c b/tests/test-blobmsg-types.c index 4d77a27..1c64b3f 100644 --- a/tests/test-blobmsg-types.c +++ b/tests/test-blobmsg-types.c @@ -19,6 +19,8 @@ enum { FOO_INT8_MIN, FOO_DOUBLE_MAX, FOO_DOUBLE_MIN, + FOO_BOOL_TRUE, + FOO_BOOL_FALSE, __FOO_MAX }; @@ -67,6 +69,14 @@ static const struct blobmsg_policy pol[] = { .name = "double_min", .type = BLOBMSG_TYPE_DOUBLE, }, + [FOO_BOOL_TRUE] = { + .name = "bool_true", + .type = BLOBMSG_TYPE_BOOL, + }, + [FOO_BOOL_FALSE] = { + .name = "bool_false", + .type = BLOBMSG_TYPE_BOOL, + }, }; static const struct blobmsg_policy pol_json[] = { @@ -100,11 +110,11 @@ static const struct blobmsg_policy pol_json[] = { }, [FOO_INT8_MAX] = { .name = "int8_max", - .type = BLOBMSG_TYPE_INT8, + .type = BLOBMSG_TYPE_INT32, }, [FOO_INT8_MIN] = { .name = "int8_min", - .type = BLOBMSG_TYPE_INT8, + .type = BLOBMSG_TYPE_INT32, }, [FOO_DOUBLE_MAX] = { .name = "double_max", @@ -114,6 +124,14 @@ static const struct blobmsg_policy pol_json[] = { .name = "double_min", .type = BLOBMSG_TYPE_DOUBLE, }, + [FOO_BOOL_TRUE] = { + .name = "bool_true", + .type = BLOBMSG_TYPE_BOOL, + }, + [FOO_BOOL_FALSE] = { + .name = "bool_false", + .type = BLOBMSG_TYPE_BOOL, + }, }; #ifndef ARRAY_SIZE @@ -150,6 +168,10 @@ static void dump_message(struct blob_buf *buf) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %s\n", blobmsg_get_bool(tb[FOO_BOOL_TRUE]) ? "true" : "false"); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %s\n", blobmsg_get_bool(tb[FOO_BOOL_FALSE]) ? "true" : "false"); } static void dump_message_cast_u64(struct blob_buf *buf) @@ -182,6 +204,10 @@ static void dump_message_cast_u64(struct blob_buf *buf) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_BOOL_TRUE])); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_BOOL_FALSE])); } static void dump_message_cast_s64(struct blob_buf *buf) @@ -214,6 +240,10 @@ static void dump_message_cast_s64(struct blob_buf *buf) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_BOOL_TRUE])); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_BOOL_FALSE])); } static void dump_message_json(struct blob_buf *buf) @@ -240,16 +270,20 @@ static void dump_message_json(struct blob_buf *buf) /* u16 is unknown to json, retrieve as u32 */ if (tb[FOO_INT16_MIN]) fprintf(stderr, "int16_min: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT16_MIN])); - /* u8 is converted to boolean (true: all values != 0/false: value 0) in json */ + /* u8 is unknown to json, retrieve as u32 */ if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRId8 "\n", blobmsg_get_u8(tb[FOO_INT8_MAX])); - /* u8 is converted to boolean (true: all values != 0/false: value 0) in json */ + fprintf(stderr, "int8_max: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT8_MAX])); + /* u8 is unknown to json, retrieve as u32 */ if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRId8 "\n", blobmsg_get_u8(tb[FOO_INT8_MIN])); + fprintf(stderr, "int8_min: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT8_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %s\n", blobmsg_get_bool(tb[FOO_BOOL_TRUE]) ? "true" : "false"); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %s\n", blobmsg_get_bool(tb[FOO_BOOL_FALSE]) ? "true" : "false"); } static void dump_message_cast_u64_json(struct blob_buf *buf) @@ -282,6 +316,10 @@ static void dump_message_cast_u64_json(struct blob_buf *buf) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_BOOL_TRUE])); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_BOOL_FALSE])); } static void dump_message_cast_s64_json(struct blob_buf *buf) @@ -314,6 +352,10 @@ static void dump_message_cast_s64_json(struct blob_buf *buf) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) fprintf(stderr, "double_min: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MIN])); + if (tb[FOO_BOOL_TRUE]) + fprintf(stderr, "bool_true: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_BOOL_TRUE])); + if (tb[FOO_BOOL_FALSE]) + fprintf(stderr, "bool_false: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_BOOL_FALSE])); } static void @@ -330,6 +372,8 @@ fill_message(struct blob_buf *buf) blobmsg_add_u8(buf, "int8_min", INT8_MIN); blobmsg_add_double(buf, "double_max", DBL_MAX); blobmsg_add_double(buf, "double_min", DBL_MIN); + blobmsg_add_bool(buf, "bool_true", true); + blobmsg_add_bool(buf, "bool_false", false); } int main(int argc, char **argv)