aboutsummaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:48:51 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:50:10 +0200
commit2467922d47a579d447406eddcecdb1127d33213b (patch)
treeeec67e28e65687ad140e775b948801e1022000ed /pb.h
parent9dd81c51b3c64221117ad2c71daff0980baaf1c2 (diff)
Zero-valued extension fields were mistakenly ignored by encoder. (issue #242)
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/pb.h b/pb.h
index f68d1d65..f68a1cc0 100644
--- a/pb.h
+++ b/pb.h
@@ -478,9 +478,14 @@ struct pb_extension_s {
{tag, PB_ATYPE_CALLBACK | PB_HTYPE_REPEATED | ltype, \
fd, 0, pb_membersize(st, m), 0, ptr}
-/* Optional extensions don't have the has_ field, as that would be redundant. */
+/* Optional extensions don't have the has_ field, as that would be redundant.
+ * Furthermore, the combination of OPTIONAL without has_ field is used
+ * for indicating proto3 style fields. Extensions exist in proto2 mode only,
+ * so they should be encoded according to proto2 rules. To avoid the conflict,
+ * extensions are marked as REQUIRED instead.
+ */
#define PB_OPTEXT_STATIC(tag, st, m, fd, ltype, ptr) \
- {tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \
+ {tag, PB_ATYPE_STATIC | PB_HTYPE_REQUIRED | ltype, \
0, \
0, \
pb_membersize(st, m), 0, ptr}