summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-12-23 17:26:23 -0800
committerJoshua Haberman <jhaberman@gmail.com>2018-12-23 17:26:23 -0800
commitbc916f1d0f8655c957b3de3b74370241605121ef (patch)
tree55f5fff947d8cead6d9e7a2af764c9c40336dbdd /upb
parent08987e3dd4159cf7d1d303a81fd38c5e02a44557 (diff)
Added "add" accessors for repeated fields.
Diffstat (limited to 'upb')
-rw-r--r--upb/generated_util.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/upb/generated_util.h b/upb/generated_util.h
index 9c5e189..5d6ccb4 100644
--- a/upb/generated_util.h
+++ b/upb/generated_util.h
@@ -42,6 +42,7 @@ UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
upb_fieldtype_t type,
upb_arena *arena) {
upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+
if (!arr) {
arr = upb_array_new(type, arena);
if (!arr) return NULL;
@@ -60,10 +61,25 @@ UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
}
arr->size = new_size;
}
+
arr->len = size;
return arr->data;
}
+UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
+ size_t elem_size,
+ upb_fieldtype_t type,
+ const void *value,
+ upb_arena *arena) {
+ upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+ size_t i = arr ? arr->len : 1;
+ void *data =
+ _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena);
+ if (!data) return false;
+ memcpy(PTR_AT(data, i * elem_size, char), value, elem_size);
+ return true;
+}
+
UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
return (*PTR_AT(msg, idx / 8, const char) & (idx % 8)) != 0;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback