summaryrefslogtreecommitdiff
path: root/upb/msg.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-12-13 07:12:58 -0800
committerJoshua Haberman <jhaberman@gmail.com>2018-12-13 07:12:58 -0800
commit6bcdaa13528bd9b924705ae9835dd8f0ca0337d5 (patch)
treebe91afb3af543e73d8b5d5fd873c23d77d138d00 /upb/msg.h
parent2c0e0054a85651ff20067ec504844a4611097041 (diff)
Changed generated array accessors to be more convenient.
Diffstat (limited to 'upb/msg.h')
-rw-r--r--upb/msg.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/upb/msg.h b/upb/msg.h
index c72e9f0..22811d8 100644
--- a/upb/msg.h
+++ b/upb/msg.h
@@ -24,6 +24,7 @@
#include "upb/def.h"
#include "upb/handlers.h"
#include "upb/sink.h"
+#include "upb/structs.int.h"
#ifdef __cplusplus
@@ -209,6 +210,31 @@ bool upb_msg_clearfield(upb_msg *msg,
* semantics are the same as upb_msg. A upb_array allocates dynamic
* memory internally for the array elements. */
+UPB_INLINE const void *_upb_array_accessor(const upb_array *arr, size_t *size) {
+ if (size) *size = arr->size;
+ return arr->data;
+}
+
+UPB_INLINE void *_upb_array_mutable_accessor(upb_array *arr, size_t *size) {
+ if (size) *size = arr->size;
+ return arr->data;
+}
+
+UPB_INLINE void *_upb_array_resize_accessor(upb_array *arr, size_t size,
+ size_t elem_size) {
+ if (size > arr->size) {
+ size_t new_size = UPB_MAX(arr->size, 4);
+ size_t old_bytes = arr->size * elem_size;
+ size_t new_bytes;
+ upb_alloc *alloc = upb_arena_alloc(arr->arena);
+ while (new_size < size) new_size *= 2;
+ new_bytes = new_size * elem_size;
+ arr->data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
+ }
+ arr->len = size;
+ return arr->data;
+}
+
upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a);
upb_fieldtype_t upb_array_type(const upb_array *arr);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback