diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 16:41:04 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 16:41:04 -0700 |
commit | bda3269a42877ae0a0b2b44b579cba5b13d5b1de (patch) | |
tree | 60bc46bda5615b93f59cf129bd3089f38be4ba3d /upb/upb.h | |
parent | 7175edb10a51e5931efd14cdb8cf62ce3463c85e (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.h | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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)); |