example_encoder.c 1.27 KB
Newer Older
Sven Robertz's avatar
Sven Robertz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader_writer.h>
#include "gen/simple.h"

int main(int argc, char *argv[]) {
  int fd;
  struct labcomm_encoder *encoder;
  int i, j;

  char *filename = argv[1];
  printf("C encoder writing to %s\n", filename);
  fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
  encoder = labcomm_encoder_new(labcomm_fd_writer, &fd);
  labcomm_encoder_register_simple_TwoInts(encoder);
  labcomm_encoder_register_simple_IntString(encoder);
18
  labcomm_encoder_register_simple_TwoArrays(encoder);
Sven Robertz's avatar
Sven Robertz committed
19
20
21
  simple_IntString is;
  is.x = 24;
  is.s = "Hello, LabComm!";
Sven Robertz's avatar
Sven Robertz committed
22
  printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
Sven Robertz's avatar
Sven Robertz committed
23
24
25
26
27
  labcomm_encode_simple_IntString(encoder, &is);

  simple_TwoInts ti;
  ti.a = 13;
  ti.b = 37;
Sven Robertz's avatar
Sven Robertz committed
28
  printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
Sven Robertz's avatar
Sven Robertz committed
29
  labcomm_encode_simple_TwoInts(encoder, &ti);
30

Sven Robertz's avatar
Sven Robertz committed
31
  int foo[20];
32
33
34
35

  simple_TwoArrays ta;
  ta.fixed.a[0] = 17;
  ta.fixed.a[1] = 42;
Sven Robertz's avatar
Sven Robertz committed
36
  ta.variable.n_1 = 10;
37
  ta.variable.a = foo;
Sven Robertz's avatar
Sven Robertz committed
38
39
40
41
42
43
  
  int k;
  for(k=0; k<20; k++) {
	foo[k] = k;
  }

44
  printf("Encoding TwoArrays...\n");
Sven Robertz's avatar
Sven Robertz committed
45
  labcomm_encode_simple_TwoArrays(encoder, &ta);
46
47
48
49
50
51
52

  ti.a = 23;
  ti.b = 47;
  printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
  labcomm_encode_simple_TwoInts(encoder, &ti);


Sven Robertz's avatar
Sven Robertz committed
53
}