forked from DaveGamble/cJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_msgpack.c
More file actions
48 lines (39 loc) · 1.04 KB
/
Copy pathtest_msgpack.c
File metadata and controls
48 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "cJSON.h"
#include "cJSON_MsgPack.h"
void hex_dump(uint8_t *data, int len, int line_size)
{
int i;
for (i = 0; i < len; i++)
{
if (i % line_size == 0)
{
printf("\n");
}
printf("%02x ", data[i]);
}
printf("\n");
}
int main(int argc, char *argv[])
{
uint8_t *msgpack = NULL;
size_t len = 0;
cJSON *json = cJSON_CreateObject();
cJSON *node1 = cJSON_AddObjectToObject(json, "node1");
cJSON *node2 = cJSON_AddObjectToObject(json, "node2");
cJSON *node3 = cJSON_AddObjectToObject(json, "node3");
cJSON_AddStringToObject(node1, "name", "node1");
cJSON_AddNumberToObject(node1, "value", 1);
cJSON_AddStringToObject(node2, "name", "node2");
cJSON_AddNumberToObject(node2, "value", 2);
printf("json root parent: %p\n", json->parent);
msgpack = cJSON_PrintMsgPack(json, &len);
if (msgpack && len)
{
hex_dump(msgpack, len, 16);
}
return 0;
}