summaryrefslogtreecommitdiff
path: root/upb_struct.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-05-16 17:37:14 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-05-16 17:37:14 -0700
commitfdcefd68b17a62c7129e910351f5b323044f835d (patch)
tree3d25c0a3734eaa52abe0a1ba47ab17c5eef97d61 /upb_struct.c
parentd4f3e5a1afcf7137c4bed24ab856660e1ca91eda (diff)
Rethought upb_struct and new descriptor.h.
This is the next step in bootstrapping. upb_struct defines the in-memory layout that will be used by both compile-time and run-time defintions of protobufs. descriptor.h describes the proto format using this format. The next step is to create a descriptor.c that can parse descriptor protos into this format. Then real run-time reflection can begin.
Diffstat (limited to 'upb_struct.c')
-rw-r--r--upb_struct.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/upb_struct.c b/upb_struct.c
new file mode 100644
index 0000000..b0b244a
--- /dev/null
+++ b/upb_struct.c
@@ -0,0 +1,44 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Definitions that will emit code for inline functions, per C99 inlining
+ * rules (see http://www.greenend.org.uk/rjk/2003/03/inline.html).
+ */
+
+#include "upb_struct.h"
+
+#define UPB_DECLARE_ACCESSORS(ctype, name) \
+ extern ctype *upb_struct_get_ ## name ## _ptr( \
+ uint8_t *s, struct upb_struct_field *f); \
+ extern ctype upb_struct_get_ ## name( \
+ uint8_t *s, struct upb_struct_field *f); \
+ extern void upb_struct_set_ ## name( \
+ uint8_t *s, struct upb_struct_field *f, ctype val);
+
+#define UPB_DECLARE_ARRAY_ACCESSORS(ctype, name) \
+ extern ctype *upb_array_get_ ## name ## _ptr(struct upb_array *a, int n); \
+ extern ctype upb_array_get_ ## name(struct upb_array *a, int n); \
+ extern void upb_array_set_ ## name(struct upb_array *a, int n, ctype val);
+
+#define UPB_DECLARE_ALL_ACCESSORS(ctype, name) \
+ UPB_DECLARE_ACCESSORS(ctype, name) \
+ UPB_DECLARE_ARRAY_ACCESSORS(ctype, name)
+
+UPB_DECLARE_ALL_ACCESSORS(double, double)
+UPB_DECLARE_ALL_ACCESSORS(float, float)
+UPB_DECLARE_ALL_ACCESSORS(int32_t, int32)
+UPB_DECLARE_ALL_ACCESSORS(int64_t, int64)
+UPB_DECLARE_ALL_ACCESSORS(uint32_t, uint32)
+UPB_DECLARE_ALL_ACCESSORS(uint64_t, uint64)
+UPB_DECLARE_ALL_ACCESSORS(bool, bool)
+UPB_DECLARE_ALL_ACCESSORS(struct upb_struct_delimited*, bytes)
+UPB_DECLARE_ALL_ACCESSORS(struct upb_struct_delimited*, string)
+UPB_DECLARE_ALL_ACCESSORS(uint8_t*, substruct)
+UPB_DECLARE_ACCESSORS(struct upb_array*, array)
+
+extern void upb_struct_set(uint8_t *s, struct upb_struct_field *f);
+extern void upb_struct_unset(uint8_t *s, struct upb_struct_field *f);
+extern bool upb_struct_is_set(uint8_t *s, struct upb_struct_field *f);
+extern bool upb_struct_all_required_fields_set(
+ uint8_t *s, struct upb_struct_definition *d);
+extern void upb_struct_clear(uint8_t *s, struct upb_struct_definition *d);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback