1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "tpl.h"
4
5 #define S2_LEN 10
6
7 struct example {
8 char *s1; /* s1 is a pointer */
9 char s2[S2_LEN]; /* s2 is a byte array */
10 };
11
main()12 int main() {
13 tpl_node *tn;
14 int i;
15 struct example dst, src = {
16 /* .s1 = */ "string",
17 /* .s2 = */ {'b','y','t','e',' ','a','r','r','a','y'}
18 };
19
20 tn = tpl_map( "S(sc#)", &src, S2_LEN); /* NOTE S(...) */
21 tpl_pack( tn, 0 );
22 tpl_dump( tn, TPL_FILE, "/tmp/test77.tpl" );
23 tpl_free( tn );
24
25 /* unpack it now into another struct */
26
27 tn = tpl_map( "S(sc#)", &dst, S2_LEN);
28 tpl_load( tn, TPL_FILE, "/tmp/test77.tpl" );
29 tpl_unpack( tn, 0 );
30 tpl_free( tn );
31
32 printf("%s\n", dst.s1);
33 for(i=0; i < S2_LEN; i++) printf("%c", dst.s2[i]);
34 printf("\n");
35
36 free(dst.s1); /* tpl allocated it for us; we must free it */
37 return(0);
38 }
39