1 #include <stdio.h>
2 #include <string.h>
3 #include <inttypes.h>
4 #include "tpl.h"
5
6 const char *filename = "/tmp/test111.tpl";
7
8 #define NUM 100
9
10 struct st {
11 int i;
12 char c;
13 double f;
14 uint16_t v[2];
15 };
16
17
main()18 int main() {
19 struct st s[NUM], d[NUM];
20 tpl_node *tn;
21 int i;
22
23 memset(s, 0, sizeof(s)); /* clear s */
24 memset(d, 0, sizeof(d)); /* clear d */
25
26 /* fill s with random stuff */
27 for(i=0; i < NUM; i++) {
28 s[i].i = i; s[i].c='a'+i; s[i].f = 3.14159 * i; s[i].v[0] = NUM*i; s[i].v[1] = NUM+i;
29 }
30
31 tn = tpl_map("S(icfv#)#", s, 2, NUM);
32 tpl_pack(tn,0);
33 tpl_dump(tn,TPL_FILE,filename);
34 tpl_free(tn);
35
36 tn = tpl_map("S(icfv#)#", d, 2, NUM);
37 tpl_load(tn,TPL_FILE,filename);
38 tpl_unpack(tn,0);
39 tpl_free(tn);
40
41 /* see if the result is the same as the s */
42 printf("structures %s\n", (!memcmp(d,s,sizeof(d)))? "match" : "mismatch");
43 return 0;
44 }
45
46