summaryrefslogtreecommitdiff
path: root/upb/table.int.h
diff options
context:
space:
mode:
authorBo Yang <teboring@google.com>2018-03-09 19:26:20 +0000
committerBo Yang <teboring@google.com>2018-03-11 16:57:44 +0000
commitf30dd0ff0cead9bb1f8f3b1b295392d75705486b (patch)
treede4d4673be3e2f0a4c1abcb259527bbb552e1646 /upb/table.int.h
parent5029aa439c5f4cc2faebeae4a97ce9bcd7ca8281 (diff)
Prepare upb_value for encoding/decoding map.
Diffstat (limited to 'upb/table.int.h')
-rw-r--r--upb/table.int.h43
1 files changed, 18 insertions, 25 deletions
diff --git a/upb/table.int.h b/upb/table.int.h
index 225235e..610e3bc 100644
--- a/upb/table.int.h
+++ b/upb/table.int.h
@@ -24,10 +24,6 @@
#include <string.h>
#include "upb/upb.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* upb_value ******************************************************************/
@@ -49,7 +45,7 @@ typedef enum {
} upb_ctype_t;
typedef struct {
- uint64_t val;
+ upb_msgval val;
#ifndef NDEBUG
/* In debug mode we carry the value type around also so we can check accesses
* to be sure the right member is being read. */
@@ -73,13 +69,13 @@ UPB_INLINE char *upb_gstrdup(const char *s) {
return upb_strdup(s, &upb_alloc_global);
}
-UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
+UPB_INLINE void _upb_value_setval(upb_value *v, upb_msgval val,
upb_ctype_t ctype) {
v->val = val;
SET_TYPE(v->ctype, ctype);
}
-UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
+UPB_INLINE upb_value _upb_value_val(upb_msgval val, upb_ctype_t ctype) {
upb_value ret;
_upb_value_setval(&ret, val, ctype);
return ret;
@@ -95,7 +91,7 @@ UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
* upb_value upb_value_int32(int32_t val); */
#define FUNCS(name, membername, type_t, converter, proto_type) \
UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
- val->val = (converter)cval; \
+ val->val = upb_msgval_ ## converter(cval); \
SET_TYPE(val->ctype, proto_type); \
} \
UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
@@ -105,18 +101,18 @@ UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
} \
UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
- return (type_t)(converter)val.val; \
+ return (type_t)upb_msgval_get ## converter(val.val); \
}
-FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
-FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
-FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
-FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
-FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
-FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
-FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
-FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR)
-FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR)
+FUNCS(int32, int32, int32_t, int32, UPB_CTYPE_INT32)
+FUNCS(int64, int64, int64_t, int64, UPB_CTYPE_INT64)
+FUNCS(uint32, uint32, uint32_t, uint32, UPB_CTYPE_UINT32)
+FUNCS(uint64, uint64, uint64_t, uint64, UPB_CTYPE_UINT64)
+FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
+FUNCS(cstr, cstr, char*, cstr, UPB_CTYPE_CSTR)
+FUNCS(ptr, ptr, void*, ptr, UPB_CTYPE_PTR)
+FUNCS(constptr, constptr, const void*, constptr, UPB_CTYPE_CONSTPTR)
+FUNCS(fptr, fptr, upb_func*, fptr, UPB_CTYPE_FPTR)
#undef FUNCS
@@ -187,7 +183,7 @@ UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
* This separate definition is necessary because in C++, UINTPTR_MAX isn't
* reliably available. */
typedef struct {
- uint64_t val;
+ upb_msgval val;
} upb_tabval;
#else
@@ -218,7 +214,7 @@ typedef union {
} staticinit;
/* The normal accessor that we use for everything at runtime. */
- uint64_t val;
+ upb_msgval val;
} upb_tabval;
#ifdef UPB_PTR_IS_64BITS
@@ -352,7 +348,7 @@ static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
}
UPB_INLINE bool upb_arrhas(upb_tabval key) {
- return key.val != (uint64_t)-1;
+ return key.val.u64 != (uint64_t)-1;
}
/* Initialize and uninitialize a table, respectively. If memory allocation
@@ -589,9 +585,6 @@ void upb_inttable_iter_setdone(upb_inttable_iter *i);
bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
const upb_inttable_iter *i2);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
+UPB_END_EXTERN_C
#endif /* UPB_TABLE_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback