From d1aa095cb30da50c1dac4263233b45c3a9ab726e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 17 Jun 2009 13:08:06 -0700 Subject: High-level parsing interface written (not yet tested). --- upb_struct.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'upb_struct.h') diff --git a/upb_struct.h b/upb_struct.h index c43fdca..d46b007 100644 --- a/upb_struct.h +++ b/upb_struct.h @@ -70,14 +70,14 @@ struct upb_struct_field *upb_struct_find_field_by_number( /* Represents a string or bytes. */ struct upb_string { size_t byte_len; - uint8_t *data; + void *data; }; /* Represents an array (a repeated field) of any type. The interpretation of * the data in the array depends on the type. */ struct upb_array { size_t len; /* Measured in elements. */ - uint8_t *data; /* Size of individual elements is based on type. */ + void *data; /* Size of individual elements is based on type. */ }; /* A generic array of structs, using void* instead of specific types. */ @@ -121,9 +121,9 @@ UPB_DEFINE_PRIMITIVE_ARRAY(bool, bool) /* For each primitive type we define a set of six functions: * * // For fetching out of a struct (s points to the raw struct data). - * int32_t *upb_struct_get_int32_ptr(uint8_t *s, struct upb_struct_field *f); - * int32_t upb_struct_get_int32(uint8_t *s, struct upb_struct_field *f); - * void upb_struct_set_int32(uint8_t *s, struct upb_struct_field *f, int32_t val); + * int32_t *upb_struct_get_int32_ptr(void *s, struct upb_struct_field *f); + * int32_t upb_struct_get_int32(void *s, struct upb_struct_field *f); + * void upb_struct_set_int32(void *s, struct upb_struct_field *f, int32_t val); * * // For fetching out of an array. * int32_t *upb_array_get_int32_ptr(struct upb_array *a, int n); @@ -137,15 +137,15 @@ UPB_DEFINE_PRIMITIVE_ARRAY(bool, bool) #define UPB_DEFINE_ACCESSORS(ctype, name, INLINE) \ INLINE ctype *upb_struct_get_ ## name ## _ptr( \ - uint8_t *s, struct upb_struct_field *f) { \ - return (ctype*)(s + f->byte_offset); \ + void *s, struct upb_struct_field *f) { \ + return (ctype*)((char*)s + f->byte_offset); \ } \ INLINE ctype upb_struct_get_ ## name( \ - uint8_t *s, struct upb_struct_field *f) { \ + void *s, struct upb_struct_field *f) { \ return *upb_struct_get_ ## name ## _ptr(s, f); \ } \ INLINE void upb_struct_set_ ## name( \ - uint8_t *s, struct upb_struct_field *f, ctype val) { \ + void *s, struct upb_struct_field *f, ctype val) { \ *upb_struct_get_ ## name ## _ptr(s, f) = val; \ } @@ -173,42 +173,42 @@ UPB_DEFINE_ALL_ACCESSORS(uint64_t, uint64, INLINE) UPB_DEFINE_ALL_ACCESSORS(bool, bool, INLINE) UPB_DEFINE_ALL_ACCESSORS(struct upb_struct_delimited*, bytes, INLINE) UPB_DEFINE_ALL_ACCESSORS(struct upb_struct_delimited*, string, INLINE) -UPB_DEFINE_ALL_ACCESSORS(uint8_t*, substruct, INLINE) +UPB_DEFINE_ALL_ACCESSORS(void*, substruct, INLINE) UPB_DEFINE_ACCESSORS(struct upb_array*, array, INLINE) /* Functions for reading and writing the "set" flags in the pbstruct. Note * that these do not perform any memory management associated with any dynamic * memory these fields may be referencing; that is the client's responsibility. * These *only* set and test the flags. */ -INLINE void upb_struct_set(uint8_t *s, struct upb_struct_field *f) +INLINE void upb_struct_set(void *s, struct upb_struct_field *f) { - s[f->isset_byte_offset] |= f->isset_byte_mask; + ((char*)s)[f->isset_byte_offset] |= f->isset_byte_mask; } -INLINE void upb_struct_unset(uint8_t *s, struct upb_struct_field *f) +INLINE void upb_struct_unset(void *s, struct upb_struct_field *f) { - s[f->isset_byte_offset] &= ~f->isset_byte_mask; + ((char*)s)[f->isset_byte_offset] &= ~f->isset_byte_mask; } -INLINE bool upb_struct_is_set(uint8_t *s, struct upb_struct_field *f) +INLINE bool upb_struct_is_set(void *s, struct upb_struct_field *f) { - return s[f->isset_byte_offset] & f->isset_byte_mask; + return ((char*)s)[f->isset_byte_offset] & f->isset_byte_mask; } INLINE bool upb_struct_all_required_fields_set( - uint8_t *s, struct upb_struct_definition *d) + void *s, struct upb_struct_definition *d) { int num_fields = d->num_required_fields; int i = 0; while(num_fields > 8) { - if(s[i++] != 0xFF) return false; + if(((uint8_t*)s)[i++] != 0xFF) return false; num_fields -= 8; } - if(s[i] != (1 << num_fields) - 1) return false; + if(((uint8_t*)s)[i] != (1 << num_fields) - 1) return false; return true; } -INLINE void upb_struct_clear(uint8_t *s, struct upb_struct_definition *d) +INLINE void upb_struct_clear(void *s, struct upb_struct_definition *d) { memset(s, 0, d->set_flags_bytes); } -- cgit v1.2.3