Separate field iterator logic from pb_decode to pb_common.
[apps/agl-service-can-low-level.git] / pb_common.h
1 /* pb_common.h: Common support functions for pb_encode.c and pb_decode.c.
2  * These functions are rarely needed by applications directly.
3  */
4
5 #ifndef _PB_COMMON_H_
6 #define _PB_COMMON_H_
7
8 #include "pb.h"
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 /* Iterator for pb_field_t list */
15 typedef struct {
16     const pb_field_t *start;       /* Start of the pb_field_t array */
17     const pb_field_t *pos;         /* Current position of the iterator */
18     unsigned required_field_index; /* Zero-based index that counts only the required fields */
19     void *dest_struct;             /* Pointer to the destination structure to decode to */
20     void *pData;                   /* Pointer where to store current field value */
21     void *pSize;                   /* Pointer where to store the size of current array field */
22 } pb_field_iter_t;
23
24 /* Initialize the field iterator structure to beginning. */
25 void pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct);
26
27 /* Advance the iterator to the next field.
28  * Returns false when the iterator wraps back to the first field. */
29 bool pb_field_iter_next(pb_field_iter_t *iter);
30
31 /* Advance the iterator until it points at a field with the given tag.
32  * Returns false if no such field exists. */
33 bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag);
34
35 #ifdef __cplusplus
36 } /* extern "C" */
37 #endif
38
39 #endif
40