summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-29 12:13:02 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-29 12:13:02 -0700
commit60e7933d4cfd8dd98ff2076d9dacd572bc51a5f9 (patch)
treea6251b8119669d178fa2f1d4c97495e0c36424b6 /src
parent4f205f3dc372df2f4cdf47aaaee65f04aa3c361d (diff)
Tweak the prototype for the wvtov conversions.
Diffstat (limited to 'src')
-rw-r--r--src/upb_parse.h45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/upb_parse.h b/src/upb_parse.h
index dfcb534..2982b51 100644
--- a/src/upb_parse.h
+++ b/src/upb_parse.h
@@ -206,8 +206,8 @@ INLINE upb_status_t upb_get_f_uint64_t(uint8_t *buf, uint8_t *end,
* functions to call if you want to decode a value for a known type. */
/* Performs zig-zag decoding, which is used by sint32 and sint64. */
-INLINE int32_t zz_decode_32(uint32_t n) { return (n >> 1) ^ -(int32_t)(n & 1); }
-INLINE int64_t zz_decode_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); }
+INLINE int32_t upb_zzdec_32(uint32_t n) { return (n >> 1) ^ -(int32_t)(n & 1); }
+INLINE int64_t upb_zzdec_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); }
/* Use macros to define a set of two functions for each .proto type:
*
@@ -224,14 +224,14 @@ INLINE int64_t zz_decode_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); }
*/
#define WVTOV(type, wire_t, val_t) \
- INLINE void upb_wvtov_ ## type(wire_t s, val_t *d)
+ INLINE val_t upb_wvtov_ ## type(wire_t s)
#define GET(type, v_or_f, wire_t, val_t, member_name) \
INLINE upb_status_t upb_get_ ## type(uint8_t *buf, uint8_t *end, val_t *d, \
uint8_t **outbuf) { \
wire_t tmp; \
UPB_CHECK(upb_get_ ## v_or_f ## _ ## wire_t(buf, end, &tmp, outbuf)); \
- upb_wvtov_ ## type(tmp, d); \
+ *d = upb_wvtov_ ## type(tmp); \
return UPB_STATUS_OK; \
}
@@ -240,20 +240,29 @@ INLINE int64_t zz_decode_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); }
GET(type, v_or_f, wire_t, val_t, member_name) \
WVTOV(type, wire_t, val_t)
-T(DOUBLE, f, uint64_t, double, _double) { memcpy(d, &s, sizeof(double)); }
-T(FLOAT, f, uint32_t, float, _float) { memcpy(d, &s, sizeof(float)); }
-T(INT32, v, uint32_t, int32_t, int32) { *d = (int32_t)s; }
-T(INT64, v, uint64_t, int64_t, int64) { *d = (int64_t)s; }
-T(UINT32, v, uint32_t, uint32_t, uint32) { *d = s; }
-T(UINT64, v, uint64_t, uint64_t, uint64) { *d = s; }
-T(SINT32, v, uint32_t, int32_t, int32) { *d = zz_decode_32(s); }
-T(SINT64, v, uint64_t, int64_t, int64) { *d = zz_decode_64(s); }
-T(FIXED32, f, uint32_t, uint32_t, uint32) { *d = s; }
-T(FIXED64, f, uint64_t, uint64_t, uint64) { *d = s; }
-T(SFIXED32, f, uint32_t, int32_t, int32) { *d = (int32_t)s; }
-T(SFIXED64, f, uint64_t, int64_t, int64) { *d = (int64_t)s; }
-T(BOOL, v, uint32_t, bool, _bool) { *d = (bool)s; }
-T(ENUM, v, uint32_t, int32_t, int32) { *d = (int32_t)s; }
+T(INT32, v, uint32_t, int32_t, int32) { return (int32_t)s; }
+T(INT64, v, uint64_t, int64_t, int64) { return (int64_t)s; }
+T(UINT32, v, uint32_t, uint32_t, uint32) { return s; }
+T(UINT64, v, uint64_t, uint64_t, uint64) { return s; }
+T(SINT32, v, uint32_t, int32_t, int32) { return upb_zzdec_32(s); }
+T(SINT64, v, uint64_t, int64_t, int64) { return upb_zzdec_64(s); }
+T(FIXED32, f, uint32_t, uint32_t, uint32) { return s; }
+T(FIXED64, f, uint64_t, uint64_t, uint64) { return s; }
+T(SFIXED32, f, uint32_t, int32_t, int32) { return (int32_t)s; }
+T(SFIXED64, f, uint64_t, int64_t, int64) { return (int64_t)s; }
+T(BOOL, v, uint32_t, bool, _bool) { return (bool)s; }
+T(ENUM, v, uint32_t, int32_t, int32) { return (int32_t)s; }
+T(DOUBLE, f, uint64_t, double, _double) {
+ union upb_value v;
+ v.uint64 = s;
+ return v._double;
+}
+T(FLOAT, f, uint32_t, float, _float) {
+ union upb_value v;
+ v.uint32 = s;
+ return v._float;
+}
+
#undef WVTOV
#undef GET
#undef T
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback