summaryrefslogtreecommitdiff
path: root/upb/generated_util.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-12-23 17:27:54 -0800
committerJoshua Haberman <jhaberman@gmail.com>2018-12-23 17:27:54 -0800
commit16becd2bd655f3cf64c371b9dca026b8291b6ebd (patch)
tree43faf1e8d8613891f7f72f3647ac00e3bcd1189e /upb/generated_util.h
parent810c45a224cb94074e80719f635b080d5b5914c6 (diff)
parentbc916f1d0f8655c957b3de3b74370241605121ef (diff)
Merge branch 'arrayapi' into defcleanup
Diffstat (limited to 'upb/generated_util.h')
-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 88a983d..edd7298 100644
--- a/upb/generated_util.h
+++ b/upb/generated_util.h
@@ -43,6 +43,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;
@@ -61,10 +62,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) & (1 << (idx % 8))) != 0;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback