summaryrefslogtreecommitdiff
path: root/upb/upb.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2011-09-12 16:41:04 -0700
committerJoshua Haberman <jhaberman@gmail.com>2011-09-12 16:41:04 -0700
commitbda3269a42877ae0a0b2b44b579cba5b13d5b1de (patch)
tree60bc46bda5615b93f59cf129bd3089f38be4ba3d /upb/upb.h
parent7175edb10a51e5931efd14cdb8cf62ce3463c85e (diff)
Fleshed out fielddef default functionality.
Fixes unit test submitted by Hunter Morris (thanks!).
Diffstat (limited to 'upb/upb.h')
-rw-r--r--upb/upb.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/upb/upb.h b/upb/upb.h
index b79ca6d..e2a7dc3 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -162,6 +162,15 @@ typedef struct {
#define SET_TYPE(dest, val) dest = val
#endif
+// For each value type, define the following set of functions:
+//
+// // Get/set an int32 from a upb_value.
+// int32_t upb_value_getint32(upb_value val);
+// void upb_value_setint32(upb_value *val, int32_t cval);
+//
+// // Construct a new upb_value from an int32.
+// upb_value upb_value_int32(int32_t val);
+
#define UPB_VALUE_ACCESSORS(name, membername, ctype, proto_type) \
INLINE ctype upb_value_get ## name(upb_value val) { \
assert(val.type == proto_type); \
@@ -170,7 +179,13 @@ typedef struct {
INLINE void upb_value_set ## name(upb_value *val, ctype cval) { \
SET_TYPE(val->type, proto_type); \
val->val.membername = cval; \
+ } \
+ INLINE upb_value upb_value_ ## name(ctype val) { \
+ upb_value ret; \
+ upb_value_set ## name(&ret, val); \
+ return ret; \
}
+
UPB_VALUE_ACCESSORS(double, _double, double, UPB_TYPE(DOUBLE));
UPB_VALUE_ACCESSORS(float, _float, float, UPB_TYPE(FLOAT));
UPB_VALUE_ACCESSORS(int32, int32, int32_t, UPB_TYPE(INT32));
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback