summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pb_decode.c2
-rw-r--r--tests/alltypes.proto7
-rw-r--r--tests/test_decode3.c3
-rw-r--r--tests/test_encode3.c2
4 files changed, 13 insertions, 1 deletions
diff --git a/pb_decode.c b/pb_decode.c
index bc6df7b9..e2e89a0d 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -571,7 +571,7 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[
} while (pb_field_next(&iter));
/* Fixup if last field was also required. */
- if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED)
+ if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED && iter.current->tag)
req_field_count++;
/* Check the whole bytes */
diff --git a/tests/alltypes.proto b/tests/alltypes.proto
index b9003a79..ce922c13 100644
--- a/tests/alltypes.proto
+++ b/tests/alltypes.proto
@@ -6,6 +6,10 @@ message SubMessage {
optional fixed32 substuff3 = 3 [default = 3];
}
+message EmptyMessage {
+
+}
+
enum MyEnum {
Zero = 0;
First = 1;
@@ -34,6 +38,7 @@ message AllTypes {
required bytes req_bytes = 15 [(nanopb).max_size = 16];
required SubMessage req_submsg = 16;
required MyEnum req_enum = 17;
+ required EmptyMessage req_emptymsg = 18;
repeated int32 rep_int32 = 21 [(nanopb).max_count = 5];
@@ -56,6 +61,7 @@ message AllTypes {
repeated bytes rep_bytes = 35 [(nanopb).max_size = 16, (nanopb).max_count = 5];
repeated SubMessage rep_submsg = 36 [(nanopb).max_count = 5];
repeated MyEnum rep_enum = 37 [(nanopb).max_count = 5];
+ repeated EmptyMessage rep_emptymsg = 38 [(nanopb).max_count = 5];
optional int32 opt_int32 = 41 [default = 4041];
optional int64 opt_int64 = 42 [default = 4042];
@@ -77,6 +83,7 @@ message AllTypes {
optional bytes opt_bytes = 55 [(nanopb).max_size = 16, default = "4055"];
optional SubMessage opt_submsg = 56;
optional MyEnum opt_enum = 57 [default = Second];
+ optional EmptyMessage opt_emptymsg = 58;
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
diff --git a/tests/test_decode3.c b/tests/test_decode3.c
index cd1b154b..55d025c0 100644
--- a/tests/test_decode3.c
+++ b/tests/test_decode3.c
@@ -76,6 +76,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
TEST(alltypes.rep_submsg[4].substuff3 == 2016 && alltypes.rep_submsg[0].substuff3 == 3);
TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero);
+ TEST(alltypes.rep_emptymsg_count == 5);
if (mode == 0)
{
@@ -120,6 +121,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
TEST(alltypes.opt_submsg.substuff3 == 3);
TEST(alltypes.has_opt_enum == false);
TEST(alltypes.opt_enum == MyEnum_Second);
+ TEST(alltypes.has_opt_emptymsg == false);
}
else
{
@@ -164,6 +166,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
TEST(alltypes.opt_submsg.substuff3 == 3);
TEST(alltypes.has_opt_enum == true);
TEST(alltypes.opt_enum == MyEnum_Truth);
+ TEST(alltypes.has_opt_emptymsg == true);
}
TEST(alltypes.end == 1099);
diff --git a/tests/test_encode3.c b/tests/test_encode3.c
index 6db37fdc..4f6859ac 100644
--- a/tests/test_encode3.c
+++ b/tests/test_encode3.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv)
alltypes.rep_submsg[4].substuff3 = 2016;
alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
+ alltypes.rep_emptymsg_count = 5;
if (mode != 0)
{
@@ -107,6 +108,7 @@ int main(int argc, char **argv)
alltypes.opt_submsg.substuff2 = 3056;
alltypes.has_opt_enum = true;
alltypes.opt_enum = MyEnum_Truth;
+ alltypes.has_opt_emptymsg = true;
}
alltypes.end = 1099;