X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=pb_decode.c;h=a079556ed8c1259709c24e831ee8d0eb3bc149cc;hb=3c10e6fa71cbee85c540c0702a5a95333cd3be32;hp=7eda89a44217bf7dc5d3f8715780e53b45c14365;hpb=6a022985845a0a50b32b7c1fb22f9aee1f675825;p=apps%2Fagl-service-can-low-level.git diff --git a/pb_decode.c b/pb_decode.c index 7eda89a4..a079556e 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -308,12 +308,12 @@ static bool pb_field_next(pb_field_iterator_t *iter) prev_size *= iter->pos->array_size; } - if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED) - iter->required_field_index++; - if (iter->pos->tag == 0) return false; /* Only happens with empty message types */ + if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED) + iter->required_field_index++; + iter->pos++; iter->field_index++; if (iter->pos->tag == 0) @@ -430,11 +430,11 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type if (!pb_make_string_substream(stream, &substream)) return false; - while (substream.bytes_left) + do { if (!pCallback->funcs.decode(&substream, iter->pos, arg)) PB_RETURN_ERROR(stream, "callback failed"); - } + } while (substream.bytes_left); pb_close_string_substream(stream, &substream); return true; @@ -603,6 +603,19 @@ bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void return pb_decode_noinit(stream, fields, dest_struct); } +bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct) +{ + pb_istream_t substream; + bool status; + + if (!pb_make_string_substream(stream, &substream)) + return false; + + status = pb_decode(&substream, fields, dest_struct); + pb_close_string_substream(stream, &substream); + return status; +} + /* Field decoders */ bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest)