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

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

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

27
  simple_theTwoInts ti;
Sven Robertz's avatar
Sven Robertz committed
28
29
  ti.a = 13;
  ti.b = 37;
30
31
32
33
34
35
36
37
  printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
  labcomm_encode_simple_theTwoInts(encoder, &ti);

  simple_anotherTwoInts ati;
  ati.a = 23;
  ati.b = 47;
  printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b);
  labcomm_encode_simple_anotherTwoInts(encoder, &ati);
38

Sven Robertz's avatar
Sven Robertz committed
39
  int foo[20];
40

41
42
  labcomm_encoder_register_simple_TwoArrays(encoder);

43
44
45
  simple_TwoArrays ta;
  ta.fixed.a[0] = 17;
  ta.fixed.a[1] = 42;
Sven Robertz's avatar
Sven Robertz committed
46
  ta.variable.n_1 = 10;
47
  ta.variable.a = foo;
Sven Robertz's avatar
Sven Robertz committed
48
49
50
51
52
53
  
  int k;
  for(k=0; k<20; k++) {
	foo[k] = k;
  }

54
  printf("Encoding TwoArrays...\n");
Sven Robertz's avatar
Sven Robertz committed
55
  labcomm_encode_simple_TwoArrays(encoder, &ta);
56
57
58

  ti.a = 23;
  ti.b = 47;
59
60
  printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
  labcomm_encode_simple_theTwoInts(encoder, &ti);
61
62


63
64
  simple_TwoFixedArrays tfa;

65
66
67
68
69
70
71
72
73
74
  tfa.a.a[0] = 41;
  tfa.a.a[1] = 42;

  tfa.b.a[0][0] = 51;
  tfa.b.a[0][1] = 52;
  tfa.b.a[0][2] = 53;
  tfa.b.a[1][0] = 61;
  tfa.b.a[1][1] = 62;
  tfa.b.a[1][2] = 63;

75
76
77
78
  printf("Encoding TwoFixedArrays...\n");
  labcomm_encoder_register_simple_TwoFixedArrays(encoder);
  labcomm_encode_simple_TwoFixedArrays(encoder, &tfa);

79
  return 0;
Sven Robertz's avatar
Sven Robertz committed
80
}