01a37682bfc7e2d3dafa6f4f36f0ed73ae0d4261
[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 start of the structure */
20     void *pData;                   /* Pointer to current field value */
21     void *pSize;                   /* Pointer to count/has field */
22 } pb_field_iter_t;
23
24 /* Initialize the field iterator structure to beginning.
25  * Returns false if the message type is empty. */
26 bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct);
27
28 /* Advance the iterator to the next field.
29  * Returns false when the iterator wraps back to the first field. */
30 bool pb_field_iter_next(pb_field_iter_t *iter);
31
32 /* Advance the iterator until it points at a field with the given tag.
33  * Returns false if no such field exists. */
34 bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag);
35
36 #ifdef __cplusplus
37 } /* extern "C" */
38 #endif
39
40 #endif
41