forked from armink/struct2json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_struct_2_json.h
51 lines (39 loc) · 1.64 KB
/
test_struct_2_json.h
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
49
50
51
/*
yuxuebao 20180525
*/
#ifdef __cplusplus
extern "C" {
#endif
cJSON *struct_to_json_McBaseOrdrT(void* struct_obj) ;
void *json_to_struct_McBaseOrdrT(cJSON* json_obj) ;
cJSON *struct_to_json_OrderFT(void* struct_obj) ;
void *json_to_struct_OrderFT(cJSON* json_obj) ;
cJSON *struct_to_json_osSListEntryT(void* struct_obj) ;
void *json_to_struct_osSListEntryT(cJSON* json_obj) ;
cJSON *struct_to_json_OrderTT(void* struct_obj) ;
void *json_to_struct_OrderTT(cJSON* json_obj) ;
cJSON *struct_to_json_OrderT(void* struct_obj) ;
void *json_to_struct_OrderT(cJSON* json_obj) ;
#ifdef DEBUG2
#define TEST_S2J_STRUCT(type, value, file) \
type struct_obj##type; \
memset(&struct_obj##type, value, sizeof(type)); \
cJSON *json_obj##type = struct_to_json_##type(&struct_obj##type); \
char* str_json##type = cJSON_Print(json_obj##type); \
printf("%s:%s\n",#type, str_json##type); \
fprintf(file,",\n {\n \"-type\": \"%s\",\n \"value\": %s\n }", #type, str_json##type); \
free(str_json##type); \
type *p_struct_obj##type =(type *)json_to_struct_##type(json_obj##type); \
int cmp##type = memcmp(p_struct_obj##type, &struct_obj##type, sizeof(type)); \
printf("%s:memcmp:%d\n",#type, cmp##type); \
cJSON *json_obj2##type = struct_to_json_##type(p_struct_obj##type); \
str_json##type = cJSON_Print(json_obj2##type); \
printf("%s:%s\n",#type, str_json##type); \
free(str_json##type); \
s2j_delete_struct_obj(p_struct_obj##type); \
s2j_delete_json_obj(json_obj##type); \
s2j_delete_json_obj(json_obj2##type); \
#endif// DEBUG2
#ifdef __cplusplus
}
#endif /* end of __cplusplus */