summaryrefslogtreecommitdiff
path: root/upb/def.h
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2015-10-14 18:02:34 -0700
committerJosh Haberman <jhaberman@gmail.com>2015-10-14 18:02:34 -0700
commitbc53c1bc4621e172a20fb0966c7ee9342d9a8dda (patch)
tree37d3be5287e3078cfa35efc81634977236000c5a /upb/def.h
parent77d45edfb39171aef5e0ae09a471e5d8e2679a7f (diff)
Add flag to MessageDef for whether fields have presence.
Diffstat (limited to 'upb/def.h')
-rw-r--r--upb/def.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/upb/def.h b/upb/def.h
index 8f0f33b..2c29cb5 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -359,6 +359,18 @@ class upb::FieldDef {
bool IsPrimitive() const;
bool IsMap() const;
+ /* Whether this field must be able to explicitly represent presence:
+ *
+ * * This is always false for repeated fields (an empty repeated field is
+ * equivalent to a repeated field with zero entries).
+ *
+ * * This is always true for submessages.
+ *
+ * * For other fields, it depends on the message (see
+ * MessageDef::SetPrimitivesHavePresence())
+ */
+ bool HasPresence() const;
+
/* How integers are encoded. Only meaningful for integer types.
* Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */
IntegerFormat integer_format() const;
@@ -536,6 +548,7 @@ bool upb_fielddef_isstring(const upb_fielddef *f);
bool upb_fielddef_isseq(const upb_fielddef *f);
bool upb_fielddef_isprimitive(const upb_fielddef *f);
bool upb_fielddef_ismap(const upb_fielddef *f);
+bool upb_fielddef_haspresence(const upb_fielddef *f);
int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
@@ -654,6 +667,11 @@ class upb::MessageDef {
bool AddOneof(OneofDef* o, Status* s);
bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
+ /* Set this to false to indicate that primitive fields should not have
+ * explicit presence information associated with them. This will affect all
+ * fields added to this message. Defaults to true. */
+ void SetPrimitivesHavePresence(bool have_presence);
+
/* These return NULL if the field is not found. */
FieldDef* FindFieldByNumber(uint32_t number);
FieldDef* FindFieldByName(const char *name, size_t len);
@@ -847,6 +865,7 @@ bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
upb_status *s);
bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
upb_status *s);
+void upb_msgdef_setprimitiveshavepresence(upb_msgdef *m, bool have_presence);
/* Field lookup in a couple of different variations:
* - itof = int to field
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback