From fdcefd68b17a62c7129e910351f5b323044f835d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 16 May 2009 17:37:14 -0700 Subject: 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. --- upb_struct.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 upb_struct.c (limited to 'upb_struct.c') 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); -- cgit v1.2.3