From 710edcfcf111bde686713951124818b413aabe00 Mon Sep 17 00:00:00 2001 From: halosghost Date: Fri, 5 Feb 2016 17:24:53 -0600 Subject: [PATCH 1/2] First run of the generic integer packing function --- include/msgpack/pack.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/msgpack/pack.h b/include/msgpack/pack.h index 2c7120fd7..f7844c648 100644 --- a/include/msgpack/pack.h +++ b/include/msgpack/pack.h @@ -118,6 +118,29 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); #define msgpack_pack_append_buffer(user, buf, len) \ return (*(user)->callback)((user)->data, (const char*)buf, len) +#ifdef MSGPACK_C11 +#define msgpack_pack_genint(pk,i) \ + _Generic((i), char: msgpack_pack_char, \ + signed char: msgpack_pack_signed_char, \ + unsigned char: msgpack_pack_unsigned_char, \ + short: msgpack_pack_short, \ + unsigned short: msgpack_pack_unsigned_short, \ + int: msgpack_pack_int, \ + unsigned int: msgpack_pack_unsigned_int, \ + long: msgpack_pack_long, \ + unsigned long: msgpack_pack_unsigned_long, \ + long long: msgpack_pack_long_long, \ + unsigned long long: msgpack_pack_unsigned_long_long, \ + uint8_t: msgpack_pack_uint8, \ + uint16_t: msgpack_pack_uint16, \ + uint32_t: msgpack_pack_uint32, \ + uint64_t: msgpack_pack_uint64, \ + int8_t: msgpack_pack_int8, \ + int16_t: msgpack_pack_int16, \ + int32_t: msgpack_pack_int32, \ + int64_t: msgpack_pack_int64)((pk), (i)) +#endif + #include "pack_template.h" inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) From 9917ca60a7de4ed190a302f064c62bab231d8609 Mon Sep 17 00:00:00 2001 From: halosghost Date: Sun, 7 Feb 2016 11:21:54 -0600 Subject: [PATCH 2/2] Add _Generic floating-point dispatcher --- include/msgpack/pack.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/msgpack/pack.h b/include/msgpack/pack.h index f7844c648..9ce3ea0f9 100644 --- a/include/msgpack/pack.h +++ b/include/msgpack/pack.h @@ -119,7 +119,7 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); return (*(user)->callback)((user)->data, (const char*)buf, len) #ifdef MSGPACK_C11 -#define msgpack_pack_genint(pk,i) \ +#define msgpack_pack_genint(pk, i) \ _Generic((i), char: msgpack_pack_char, \ signed char: msgpack_pack_signed_char, \ unsigned char: msgpack_pack_unsigned_char, \ @@ -139,6 +139,10 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); int16_t: msgpack_pack_int16, \ int32_t: msgpack_pack_int32, \ int64_t: msgpack_pack_int64)((pk), (i)) + +#define msgpack_pack_genfloat(pk, i) \ + _Generic((i), float: msgpack_pack_float, \ + double: msgpack_pack_double)((pk), (i)) #endif #include "pack_template.h"