example.c 4.51 KB
Newer Older
1
2
3
4
5
6
#include "labcomm.h"
#include "labcomm_private.h"
#include "example.h"

static unsigned char signature_bytes_log_message[] = {
// struct { 2 fields
7
8
17, 
  2, 
9
  // int 'sequence'
10
  8, 
11
  115, 101, 113, 117, 101, 110, 99, 101, 
12
  35, 
13
  // array [_] 'line'
14
  4, 
15
16
  108, 105, 110, 101, 
  // array [_]
17
18
19
  16, 
    1, 
    0, 
20
    // struct { 2 fields
21
22
    17, 
      2, 
23
      // boolean 'last'
24
      4, 
25
      108, 97, 115, 116, 
26
      32, 
27
      // string 'data'
28
      4, 
29
      100, 97, 116, 97, 
30
      39, 
31
32
33
34
35
36
37
38
39
40
41
    // }
  // }
// }
};
labcomm_signature_t labcomm_signature_example_log_message = {
  LABCOMM_SAMPLE, "log_message",
  (int (*)(void *))labcomm_sizeof_example_log_message,
  sizeof(signature_bytes_log_message),
  signature_bytes_log_message
 };
static unsigned char signature_bytes_data[] = {
42
37, 
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
};
labcomm_signature_t labcomm_signature_example_data = {
  LABCOMM_SAMPLE, "data",
  (int (*)(void *))labcomm_sizeof_example_data,
  sizeof(signature_bytes_data),
  signature_bytes_data
 };
static void decode_log_message(
  labcomm_decoder_t *d,
  void (*handle)(
    example_log_message *v,
    void *context
  ),
  void *context
)
{
  example_log_message v;
  v.sequence = labcomm_decode_int(d);
61
  v.line.n_0 = labcomm_decode_packed32(d);
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  v.line.a = malloc(sizeof(v.line.a[0]) * v.line.n_0);
  {
    int i_0_0;
    for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) {
      int i_0 = i_0_0;
      v.line.a[i_0].last = labcomm_decode_boolean(d);
      v.line.a[i_0].data = labcomm_decode_string(d);
    }
  }
  handle(&v, context);
  {
    {
      int i_0_0;
      for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) {
        int i_0 = i_0_0;
        free(v.line.a[i_0].data);
      }
    }
    free(v.line.a);
  }
}
void labcomm_decoder_register_example_log_message(
  struct labcomm_decoder *d,
  void (*handler)(
    example_log_message *v,
    void *context
  ),
  void *context
)
{
  labcomm_internal_decoder_register(
    d,
    &labcomm_signature_example_log_message,
    (labcomm_decoder_typecast_t)decode_log_message,
    (labcomm_handler_typecast_t)handler,
    context
  );
}
static void encode_log_message(
  labcomm_encoder_t *e,
  example_log_message *v
)
{
  e->writer.write(&e->writer, labcomm_writer_start);
  labcomm_encode_type_index(e, &labcomm_signature_example_log_message);
  {
    labcomm_encode_int(e, (*v).sequence);
109
    labcomm_encode_packed32(e, (*v).line.n_0);
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    {
      int i_0_0;
      for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) {
        int i_0 = i_0_0;
        labcomm_encode_boolean(e, (*v).line.a[i_0].last);
        labcomm_encode_string(e, (*v).line.a[i_0].data);
      }
    }
  }
  e->writer.write(&e->writer, labcomm_writer_end);
}
void labcomm_encode_example_log_message(
labcomm_encoder_t *e,
example_log_message *v
)
{
labcomm_internal_encode(e, &labcomm_signature_example_log_message, v);
}
void labcomm_encoder_register_example_log_message(
  struct labcomm_encoder *e
)
{
  labcomm_internal_encoder_register(
    e,
    &labcomm_signature_example_log_message,
    (labcomm_encode_typecast_t)encode_log_message
  );
}
int labcomm_sizeof_example_log_message(example_log_message *v)
{
  int result = 4;
  {
    int i_0_0;
    for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) {
      int i_0 = i_0_0;
      result += 4 + strlen((*v).line.a[i_0].data);
      result += 1;
    }
  }
  result += 4;
  return result;
}
static void decode_data(
  labcomm_decoder_t *d,
  void (*handle)(
    example_data *v,
    void *context
  ),
  void *context
)
{
  example_data v;
  v = labcomm_decode_float(d);
  handle(&v, context);
}
void labcomm_decoder_register_example_data(
  struct labcomm_decoder *d,
  void (*handler)(
    example_data *v,
    void *context
  ),
  void *context
)
{
  labcomm_internal_decoder_register(
    d,
    &labcomm_signature_example_data,
    (labcomm_decoder_typecast_t)decode_data,
    (labcomm_handler_typecast_t)handler,
    context
  );
}
static void encode_data(
  labcomm_encoder_t *e,
  example_data *v
)
{
  e->writer.write(&e->writer, labcomm_writer_start);
  labcomm_encode_type_index(e, &labcomm_signature_example_data);
  {
    labcomm_encode_float(e, (*v));
  }
  e->writer.write(&e->writer, labcomm_writer_end);
}
void labcomm_encode_example_data(
labcomm_encoder_t *e,
example_data *v
)
{
labcomm_internal_encode(e, &labcomm_signature_example_data, v);
}
void labcomm_encoder_register_example_data(
  struct labcomm_encoder *e
)
{
  labcomm_internal_encoder_register(
    e,
    &labcomm_signature_example_data,
    (labcomm_encode_typecast_t)encode_data
  );
}
int labcomm_sizeof_example_data(example_data *v)
{
  return 8;
}