-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaddress_book.c
368 lines (325 loc) · 11.1 KB
/
address_book.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
109
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 Erik Moqvist
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* This file was generated by pbtools.
*/
#include <limits.h>
#include "address_book.h"
#if CHAR_BIT != 8
# error "Number of bits in a char must be 8."
#endif
void address_book_person_phone_number_init(
struct address_book_person_phone_number_t *self_p,
struct pbtools_heap_t *heap_p)
{
self_p->base.heap_p = heap_p;
self_p->number_p = "";
self_p->type = 0;
}
void address_book_person_phone_number_encode_inner(
struct pbtools_encoder_t *encoder_p,
struct address_book_person_phone_number_t *self_p)
{
pbtools_encoder_write_enum(encoder_p, 2, self_p->type);
pbtools_encoder_write_string(encoder_p, 1, self_p->number_p);
}
void address_book_person_phone_number_decode_inner(
struct pbtools_decoder_t *decoder_p,
struct address_book_person_phone_number_t *self_p)
{
int wire_type;
while (pbtools_decoder_available(decoder_p)) {
switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) {
case 1:
pbtools_decoder_read_string(decoder_p, wire_type, &self_p->number_p);
break;
case 2:
self_p->type = pbtools_decoder_read_enum(decoder_p, wire_type);
break;
default:
pbtools_decoder_skip_field(decoder_p, wire_type);
break;
}
}
}
void address_book_person_phone_number_encode_repeated_inner(
struct pbtools_encoder_t *encoder_p,
int field_number,
struct address_book_person_phone_number_repeated_t *repeated_p)
{
pbtools_encode_repeated_inner(
encoder_p,
field_number,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_person_phone_number_t),
(pbtools_message_encode_inner_t)address_book_person_phone_number_encode_inner);
}
void address_book_person_phone_number_decode_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct pbtools_repeated_info_t *repeated_info_p,
struct address_book_person_phone_number_repeated_t *repeated_p)
{
pbtools_decode_repeated_inner(
decoder_p,
repeated_info_p,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_person_phone_number_t),
(pbtools_message_init_t)address_book_person_phone_number_init,
(pbtools_message_decode_inner_t)address_book_person_phone_number_decode_inner);
}
void address_book_person_init(
struct address_book_person_t *self_p,
struct pbtools_heap_t *heap_p)
{
self_p->base.heap_p = heap_p;
self_p->name_p = "";
self_p->id = 0;
self_p->email_p = "";
self_p->phones.length = 0;
}
void address_book_person_encode_inner(
struct pbtools_encoder_t *encoder_p,
struct address_book_person_t *self_p)
{
address_book_person_phone_number_encode_repeated_inner(
encoder_p,
4,
&self_p->phones);
pbtools_encoder_write_string(encoder_p, 3, self_p->email_p);
pbtools_encoder_write_int32(encoder_p, 2, self_p->id);
pbtools_encoder_write_string(encoder_p, 1, self_p->name_p);
}
void address_book_person_decode_inner(
struct pbtools_decoder_t *decoder_p,
struct address_book_person_t *self_p)
{
int wire_type;
struct pbtools_repeated_info_t repeated_info_phones;
pbtools_repeated_info_init(&repeated_info_phones, 4);
while (pbtools_decoder_available(decoder_p)) {
switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) {
case 1:
pbtools_decoder_read_string(decoder_p, wire_type, &self_p->name_p);
break;
case 2:
self_p->id = pbtools_decoder_read_int32(decoder_p, wire_type);
break;
case 3:
pbtools_decoder_read_string(decoder_p, wire_type, &self_p->email_p);
break;
case 4:
pbtools_repeated_info_decode(&repeated_info_phones,
decoder_p,
wire_type);
break;
default:
pbtools_decoder_skip_field(decoder_p, wire_type);
break;
}
}
address_book_person_phone_number_decode_repeated_inner(
decoder_p,
&repeated_info_phones,
&self_p->phones);
}
int address_book_person_phones_alloc(
struct address_book_person_t *self_p,
int length)
{
return (pbtools_alloc_repeated(
(struct pbtools_repeated_message_t *)&self_p->phones,
length,
self_p->base.heap_p,
sizeof(struct address_book_person_phone_number_t),
(pbtools_message_init_t)address_book_person_phone_number_init));
}
void address_book_person_encode_repeated_inner(
struct pbtools_encoder_t *encoder_p,
int field_number,
struct address_book_person_repeated_t *repeated_p)
{
pbtools_encode_repeated_inner(
encoder_p,
field_number,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_person_t),
(pbtools_message_encode_inner_t)address_book_person_encode_inner);
}
void address_book_person_decode_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct pbtools_repeated_info_t *repeated_info_p,
struct address_book_person_repeated_t *repeated_p)
{
pbtools_decode_repeated_inner(
decoder_p,
repeated_info_p,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_person_t),
(pbtools_message_init_t)address_book_person_init,
(pbtools_message_decode_inner_t)address_book_person_decode_inner);
}
struct address_book_person_t *
address_book_person_new(
void *workspace_p,
size_t size)
{
return (pbtools_message_new(
workspace_p,
size,
sizeof(struct address_book_person_t),
(pbtools_message_init_t)address_book_person_init));
}
int address_book_person_encode(
struct address_book_person_t *self_p,
uint8_t *encoded_p,
size_t size)
{
return (pbtools_message_encode(
&self_p->base,
encoded_p,
size,
(pbtools_message_encode_inner_t)address_book_person_encode_inner));
}
int address_book_person_decode(
struct address_book_person_t *self_p,
const uint8_t *encoded_p,
size_t size)
{
return (pbtools_message_decode(
&self_p->base,
encoded_p,
size,
(pbtools_message_decode_inner_t)address_book_person_decode_inner));
}
void address_book_address_book_init(
struct address_book_address_book_t *self_p,
struct pbtools_heap_t *heap_p)
{
self_p->base.heap_p = heap_p;
self_p->people.length = 0;
}
void address_book_address_book_encode_inner(
struct pbtools_encoder_t *encoder_p,
struct address_book_address_book_t *self_p)
{
address_book_person_encode_repeated_inner(
encoder_p,
1,
&self_p->people);
}
void address_book_address_book_decode_inner(
struct pbtools_decoder_t *decoder_p,
struct address_book_address_book_t *self_p)
{
int wire_type;
struct pbtools_repeated_info_t repeated_info_people;
pbtools_repeated_info_init(&repeated_info_people, 1);
while (pbtools_decoder_available(decoder_p)) {
switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) {
case 1:
pbtools_repeated_info_decode(&repeated_info_people,
decoder_p,
wire_type);
break;
default:
pbtools_decoder_skip_field(decoder_p, wire_type);
break;
}
}
address_book_person_decode_repeated_inner(
decoder_p,
&repeated_info_people,
&self_p->people);
}
int address_book_address_book_people_alloc(
struct address_book_address_book_t *self_p,
int length)
{
return (pbtools_alloc_repeated(
(struct pbtools_repeated_message_t *)&self_p->people,
length,
self_p->base.heap_p,
sizeof(struct address_book_person_t),
(pbtools_message_init_t)address_book_person_init));
}
void address_book_address_book_encode_repeated_inner(
struct pbtools_encoder_t *encoder_p,
int field_number,
struct address_book_address_book_repeated_t *repeated_p)
{
pbtools_encode_repeated_inner(
encoder_p,
field_number,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_address_book_t),
(pbtools_message_encode_inner_t)address_book_address_book_encode_inner);
}
void address_book_address_book_decode_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct pbtools_repeated_info_t *repeated_info_p,
struct address_book_address_book_repeated_t *repeated_p)
{
pbtools_decode_repeated_inner(
decoder_p,
repeated_info_p,
(struct pbtools_repeated_message_t *)repeated_p,
sizeof(struct address_book_address_book_t),
(pbtools_message_init_t)address_book_address_book_init,
(pbtools_message_decode_inner_t)address_book_address_book_decode_inner);
}
struct address_book_address_book_t *
address_book_address_book_new(
void *workspace_p,
size_t size)
{
return (pbtools_message_new(
workspace_p,
size,
sizeof(struct address_book_address_book_t),
(pbtools_message_init_t)address_book_address_book_init));
}
int address_book_address_book_encode(
struct address_book_address_book_t *self_p,
uint8_t *encoded_p,
size_t size)
{
return (pbtools_message_encode(
&self_p->base,
encoded_p,
size,
(pbtools_message_encode_inner_t)address_book_address_book_encode_inner));
}
int address_book_address_book_decode(
struct address_book_address_book_t *self_p,
const uint8_t *encoded_p,
size_t size)
{
return (pbtools_message_decode(
&self_p->base,
encoded_p,
size,
(pbtools_message_decode_inner_t)address_book_address_book_decode_inner));
}