File: other1.cpp

package info (click to toggle)
libtpl 1.5-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 4,284 kB
  • ctags: 748
  • sloc: sh: 10,059; ansic: 5,644; perl: 1,062; makefile: 119; cpp: 32
file content (40 lines) | stat: -rwxr-xr-x 730 bytes parent folder | download | duplicates (4)
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
#include <stdio.h>
#include <string.h>
#include "tpl.h"
main() {
void *buffer;
size_t bsize;
	
struct ci {
    int i;
    char c[30];
	
	void pack( void **buffer, size_t *size )
	{
		tpl_node *tn = tpl_map("S(ic#)", this, 30);  /* pass structure address */
		tpl_pack(tn, 0);
		tpl_dump(tn, TPL_MEM, buffer, size);
		tpl_free(tn);
	}
	
	void unpack( void *buffer, size_t size )
	{
		tpl_node *tn = tpl_map("S(ic#)", this, 30);
		tpl_load(tn, TPL_MEM, buffer, size);
		tpl_unpack( tn, 0 );
		tpl_free(tn);
	}
};

struct ci s = {9999, "this is a test string."};

s.pack(&buffer, &bsize);
printf("buffer: %s\n", (char *)buffer);

struct ci b = { -1, "" };

b.unpack(buffer, bsize);

printf("i: %d\n", b.i);
printf("c: %s\n", b.c);
}