- pb_decoder_t func = PB_DECODERS[PB_LTYPE(field->type)];
- void *pData = (char*)dest_struct + field->data_offset;
- void *pSize = (char*)dest_struct + field->size_offset;
+ stream->state = substream->state;
+}
+
+/* Iterator for pb_field_t list */
+typedef struct {
+ const pb_field_t *start; /* Start of the pb_field_t array */
+ const pb_field_t *current; /* Current position of the iterator */
+ int field_index; /* Zero-based index of the field. */
+ int required_field_index; /* Zero-based index that counts only the required fields */
+ void *dest_struct; /* Pointer to the destination structure to decode to */
+ void *pData; /* Pointer where to store current field value */
+ void *pSize; /* Pointer where to store the size of current array field */
+} pb_field_iterator_t;
+
+static void pb_field_init(pb_field_iterator_t *iter, const pb_field_t *fields, void *dest_struct)
+{
+ iter->start = iter->current = fields;
+ iter->field_index = 0;
+ iter->required_field_index = 0;
+ iter->pData = (char*)dest_struct + iter->current->data_offset;
+ iter->pSize = (char*)iter->pData + iter->current->size_offset;
+ iter->dest_struct = dest_struct;
+}
+
+static bool pb_field_next(pb_field_iterator_t *iter)
+{
+ bool notwrapped = true;
+ size_t prev_size = iter->current->data_size;
+
+ if (PB_HTYPE(iter->current->type) == PB_HTYPE_ARRAY)
+ prev_size *= iter->current->array_size;