15 static const struct blobmsg_policy foo_policy
[] = {
18 .type
= BLOBMSG_TYPE_STRING
,
22 .type
= BLOBMSG_TYPE_ARRAY
,
26 .type
= BLOBMSG_TYPE_TABLE
,
30 static void dump_result(const char *fn
, int r
, const char *filename
, struct blob_attr
**tb
)
32 fprintf(stdout
, "%s: %s: %c%c%c (%d)\n", basename((char *) filename
), fn
,
33 tb
[FOO_MESSAGE
] ? 'M' : '.',
34 tb
[FOO_LIST
] ? 'L' : '.',
35 tb
[FOO_TESTDATA
] ? 'T' : '.',
39 static void test_blobmsg(const char *filename
)
46 struct blob_attr
*tb
[__FOO_MAX
];
48 fd
= fopen(filename
, "r");
50 fprintf(stderr
, "unable to open %s\n", filename
);
54 buf
= malloc(BUF_LEN
+1);
58 len
= fread(buf
, 1, BUF_LEN
, fd
);
61 r
= blobmsg_parse(foo_policy
, ARRAY_SIZE(foo_policy
), tb
, buf
, len
);
62 dump_result("blobmsg_parse", r
, filename
, tb
);
64 r
= blobmsg_parse_array(foo_policy
, ARRAY_SIZE(foo_policy
), tb
, buf
, len
);
65 dump_result("blobmsg_parse_array", r
, filename
, tb
);
70 int main(int argc
, char *argv
[])
73 fprintf(stderr
, "Usage: %s <blobmsg.bin>\n", argv
[0]);
77 test_blobmsg(argv
[1]);