s/\t/ /g
This commit is contained in:
@@ -39,269 +39,269 @@
|
|||||||
|
|
||||||
#define msgpack_pack_real_uint8(x, d) \
|
#define msgpack_pack_real_uint8(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < (1<<7)) { \
|
if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_uint16(x, d) \
|
#define msgpack_pack_real_uint16(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < (1<<7)) { \
|
if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
||||||
} else if(d < (1<<8)) { \
|
} else if(d < (1<<8)) { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_uint32(x, d) \
|
#define msgpack_pack_real_uint32(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < (1<<8)) { \
|
if(d < (1<<8)) { \
|
||||||
if(d < (1<<7)) { \
|
if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1<<16)) { \
|
if(d < (1<<16)) { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 32 */ \
|
/* unsigned 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_uint64(x, d) \
|
#define msgpack_pack_real_uint64(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < (1ULL<<8)) { \
|
if(d < (1ULL<<8)) { \
|
||||||
if(d < (1ULL<<7)) { \
|
if(d < (1ULL<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1ULL<<16)) { \
|
if(d < (1ULL<<16)) { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else if(d < (1ULL<<32)) { \
|
} else if(d < (1ULL<<32)) { \
|
||||||
/* unsigned 32 */ \
|
/* unsigned 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 64 */ \
|
/* unsigned 64 */ \
|
||||||
unsigned char buf[9]; \
|
unsigned char buf[9]; \
|
||||||
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 9); \
|
msgpack_pack_append_buffer(x, buf, 9); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_int8(x, d) \
|
#define msgpack_pack_real_int8(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < -(1<<5)) { \
|
if(d < -(1<<5)) { \
|
||||||
/* signed 8 */ \
|
/* signed 8 */ \
|
||||||
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
|
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} else { \
|
} else { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_int16(x, d) \
|
#define msgpack_pack_real_int16(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < -(1<<5)) { \
|
if(d < -(1<<5)) { \
|
||||||
if(d < -(1<<7)) { \
|
if(d < -(1<<7)) { \
|
||||||
/* signed 16 */ \
|
/* signed 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else { \
|
} else { \
|
||||||
/* signed 8 */ \
|
/* signed 8 */ \
|
||||||
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
|
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} else if(d < (1<<7)) { \
|
} else if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1<<8)) { \
|
if(d < (1<<8)) { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_int32(x, d) \
|
#define msgpack_pack_real_int32(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < -(1<<5)) { \
|
if(d < -(1<<5)) { \
|
||||||
if(d < -(1<<15)) { \
|
if(d < -(1<<15)) { \
|
||||||
/* signed 32 */ \
|
/* signed 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} else if(d < -(1<<7)) { \
|
} else if(d < -(1<<7)) { \
|
||||||
/* signed 16 */ \
|
/* signed 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else { \
|
} else { \
|
||||||
/* signed 8 */ \
|
/* signed 8 */ \
|
||||||
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
|
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} else if(d < (1<<7)) { \
|
} else if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1<<8)) { \
|
if(d < (1<<8)) { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} else if(d < (1<<16)) { \
|
} else if(d < (1<<16)) { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 32 */ \
|
/* unsigned 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define msgpack_pack_real_int64(x, d) \
|
#define msgpack_pack_real_int64(x, d) \
|
||||||
do { \
|
do { \
|
||||||
if(d < -(1LL<<5)) { \
|
if(d < -(1LL<<5)) { \
|
||||||
if(d < -(1LL<<15)) { \
|
if(d < -(1LL<<15)) { \
|
||||||
if(d < -(1LL<<31)) { \
|
if(d < -(1LL<<31)) { \
|
||||||
/* signed 64 */ \
|
/* signed 64 */ \
|
||||||
unsigned char buf[9]; \
|
unsigned char buf[9]; \
|
||||||
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
|
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 9); \
|
msgpack_pack_append_buffer(x, buf, 9); \
|
||||||
} else { \
|
} else { \
|
||||||
/* signed 32 */ \
|
/* signed 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < -(1<<7)) { \
|
if(d < -(1<<7)) { \
|
||||||
/* signed 16 */ \
|
/* signed 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} else { \
|
} else { \
|
||||||
/* signed 8 */ \
|
/* signed 8 */ \
|
||||||
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
|
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} else if(d < (1<<7)) { \
|
} else if(d < (1<<7)) { \
|
||||||
/* fixnum */ \
|
/* fixnum */ \
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1LL<<16)) { \
|
if(d < (1LL<<16)) { \
|
||||||
if(d < (1<<8)) { \
|
if(d < (1<<8)) { \
|
||||||
/* unsigned 8 */ \
|
/* unsigned 8 */ \
|
||||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||||
msgpack_pack_append_buffer(x, buf, 2); \
|
msgpack_pack_append_buffer(x, buf, 2); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 16 */ \
|
/* unsigned 16 */ \
|
||||||
unsigned char buf[3]; \
|
unsigned char buf[3]; \
|
||||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 3); \
|
msgpack_pack_append_buffer(x, buf, 3); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
if(d < (1LL<<32)) { \
|
if(d < (1LL<<32)) { \
|
||||||
/* unsigned 32 */ \
|
/* unsigned 32 */ \
|
||||||
unsigned char buf[5]; \
|
unsigned char buf[5]; \
|
||||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 5); \
|
msgpack_pack_append_buffer(x, buf, 5); \
|
||||||
} else { \
|
} else { \
|
||||||
/* unsigned 64 */ \
|
/* unsigned 64 */ \
|
||||||
unsigned char buf[9]; \
|
unsigned char buf[9]; \
|
||||||
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
||||||
msgpack_pack_append_buffer(x, buf, 9); \
|
msgpack_pack_append_buffer(x, buf, 9); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
static inline int msgpack_pack_uint8(msgpack_packer* x, uint8_t d)
|
static inline int msgpack_pack_uint8(msgpack_packer* x, uint8_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint8(x, d);
|
msgpack_pack_real_uint8(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_uint16(msgpack_packer* x, uint16_t d)
|
static inline int msgpack_pack_uint16(msgpack_packer* x, uint16_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_uint32(msgpack_packer* x, uint32_t d)
|
static inline int msgpack_pack_uint32(msgpack_packer* x, uint32_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_uint64(msgpack_packer* x, uint64_t d)
|
static inline int msgpack_pack_uint64(msgpack_packer* x, uint64_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_int8(msgpack_packer* x, int8_t d)
|
static inline int msgpack_pack_int8(msgpack_packer* x, int8_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int8(x, d);
|
msgpack_pack_real_int8(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_int16(msgpack_packer* x, int16_t d)
|
static inline int msgpack_pack_int16(msgpack_packer* x, int16_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_int32(msgpack_packer* x, int32_t d)
|
static inline int msgpack_pack_int32(msgpack_packer* x, int32_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_int64(msgpack_packer* x, int64_t d)
|
static inline int msgpack_pack_int64(msgpack_packer* x, int64_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -311,29 +311,29 @@ static inline int msgpack_pack_short(msgpack_packer* x, short d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_SHORT)
|
#if defined(SIZEOF_SHORT)
|
||||||
#if SIZEOF_SHORT == 2
|
#if SIZEOF_SHORT == 2
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif SIZEOF_SHORT == 4
|
#elif SIZEOF_SHORT == 4
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(SHRT_MAX)
|
#elif defined(SHRT_MAX)
|
||||||
#if SHRT_MAX == 0x7fff
|
#if SHRT_MAX == 0x7fff
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif SHRT_MAX == 0x7fffffff
|
#elif SHRT_MAX == 0x7fffffff
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(short) == 2) {
|
if(sizeof(short) == 2) {
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
} else if(sizeof(short) == 4) {
|
} else if(sizeof(short) == 4) {
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -342,29 +342,29 @@ static inline int msgpack_pack_int(msgpack_packer* x, int d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_INT)
|
#if defined(SIZEOF_INT)
|
||||||
#if SIZEOF_INT == 2
|
#if SIZEOF_INT == 2
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif SIZEOF_INT == 4
|
#elif SIZEOF_INT == 4
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(INT_MAX)
|
#elif defined(INT_MAX)
|
||||||
#if INT_MAX == 0x7fff
|
#if INT_MAX == 0x7fff
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif INT_MAX == 0x7fffffff
|
#elif INT_MAX == 0x7fffffff
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(int) == 2) {
|
if(sizeof(int) == 2) {
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
} else if(sizeof(int) == 4) {
|
} else if(sizeof(int) == 4) {
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -373,29 +373,29 @@ static inline int msgpack_pack_long(msgpack_packer* x, long d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG)
|
#if defined(SIZEOF_LONG)
|
||||||
#if SIZEOF_LONG == 2
|
#if SIZEOF_LONG == 2
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif SIZEOF_LONG == 4
|
#elif SIZEOF_LONG == 4
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(LONG_MAX)
|
#elif defined(LONG_MAX)
|
||||||
#if LONG_MAX == 0x7fffL
|
#if LONG_MAX == 0x7fffL
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif LONG_MAX == 0x7fffffffL
|
#elif LONG_MAX == 0x7fffffffL
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(long) == 2) {
|
if(sizeof(long) == 2) {
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
} else if(sizeof(long) == 4) {
|
} else if(sizeof(long) == 4) {
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -404,29 +404,29 @@ static inline int msgpack_pack_long_long(msgpack_packer* x, long long d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG_LONG)
|
#if defined(SIZEOF_LONG_LONG)
|
||||||
#if SIZEOF_LONG_LONG == 2
|
#if SIZEOF_LONG_LONG == 2
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif SIZEOF_LONG_LONG == 4
|
#elif SIZEOF_LONG_LONG == 4
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(LLONG_MAX)
|
#elif defined(LLONG_MAX)
|
||||||
#if LLONG_MAX == 0x7fffL
|
#if LLONG_MAX == 0x7fffL
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
#elif LLONG_MAX == 0x7fffffffL
|
#elif LLONG_MAX == 0x7fffffffL
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(long long) == 2) {
|
if(sizeof(long long) == 2) {
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
} else if(sizeof(long long) == 4) {
|
} else if(sizeof(long long) == 4) {
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -435,29 +435,29 @@ static inline int msgpack_pack_unsigned_short(msgpack_packer* x, unsigned short
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_SHORT)
|
#if defined(SIZEOF_SHORT)
|
||||||
#if SIZEOF_SHORT == 2
|
#if SIZEOF_SHORT == 2
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif SIZEOF_SHORT == 4
|
#elif SIZEOF_SHORT == 4
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(USHRT_MAX)
|
#elif defined(USHRT_MAX)
|
||||||
#if USHRT_MAX == 0xffffU
|
#if USHRT_MAX == 0xffffU
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif USHRT_MAX == 0xffffffffU
|
#elif USHRT_MAX == 0xffffffffU
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(unsigned short) == 2) {
|
if(sizeof(unsigned short) == 2) {
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
} else if(sizeof(unsigned short) == 4) {
|
} else if(sizeof(unsigned short) == 4) {
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -466,29 +466,29 @@ static inline int msgpack_pack_unsigned_int(msgpack_packer* x, unsigned int d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_INT)
|
#if defined(SIZEOF_INT)
|
||||||
#if SIZEOF_INT == 2
|
#if SIZEOF_INT == 2
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif SIZEOF_INT == 4
|
#elif SIZEOF_INT == 4
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(UINT_MAX)
|
#elif defined(UINT_MAX)
|
||||||
#if UINT_MAX == 0xffffU
|
#if UINT_MAX == 0xffffU
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif UINT_MAX == 0xffffffffU
|
#elif UINT_MAX == 0xffffffffU
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(unsigned int) == 2) {
|
if(sizeof(unsigned int) == 2) {
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
} else if(sizeof(unsigned int) == 4) {
|
} else if(sizeof(unsigned int) == 4) {
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -497,29 +497,29 @@ static inline int msgpack_pack_unsigned_long(msgpack_packer* x, unsigned long d)
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG)
|
#if defined(SIZEOF_LONG)
|
||||||
#if SIZEOF_LONG == 2
|
#if SIZEOF_LONG == 2
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif SIZEOF_LONG == 4
|
#elif SIZEOF_LONG == 4
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(ULONG_MAX)
|
#elif defined(ULONG_MAX)
|
||||||
#if ULONG_MAX == 0xffffUL
|
#if ULONG_MAX == 0xffffUL
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif ULONG_MAX == 0xffffffffUL
|
#elif ULONG_MAX == 0xffffffffUL
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(unsigned long) == 2) {
|
if(sizeof(unsigned long) == 2) {
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
} else if(sizeof(unsigned long) == 4) {
|
} else if(sizeof(unsigned long) == 4) {
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -528,29 +528,29 @@ static inline int msgpack_pack_unsigned_long_long(msgpack_packer* x, unsigned lo
|
|||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG_LONG)
|
#if defined(SIZEOF_LONG_LONG)
|
||||||
#if SIZEOF_LONG_LONG == 2
|
#if SIZEOF_LONG_LONG == 2
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif SIZEOF_LONG_LONG == 4
|
#elif SIZEOF_LONG_LONG == 4
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(ULLONG_MAX)
|
#elif defined(ULLONG_MAX)
|
||||||
#if ULLONG_MAX == 0xffffUL
|
#if ULLONG_MAX == 0xffffUL
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
#elif ULLONG_MAX == 0xffffffffUL
|
#elif ULLONG_MAX == 0xffffffffUL
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
#else
|
#else
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(sizeof(unsigned long long) == 2) {
|
if(sizeof(unsigned long long) == 2) {
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
} else if(sizeof(unsigned long long) == 4) {
|
} else if(sizeof(unsigned long long) == 4) {
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
} else {
|
} else {
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -566,25 +566,25 @@ if(sizeof(unsigned long long) == 2) {
|
|||||||
|
|
||||||
static inline int msgpack_pack_float(msgpack_packer* x, float d)
|
static inline int msgpack_pack_float(msgpack_packer* x, float d)
|
||||||
{
|
{
|
||||||
union { float f; uint32_t i; } mem;
|
union { float f; uint32_t i; } mem;
|
||||||
mem.f = d;
|
mem.f = d;
|
||||||
unsigned char buf[5];
|
unsigned char buf[5];
|
||||||
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
|
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_double(msgpack_packer* x, double d)
|
static inline int msgpack_pack_double(msgpack_packer* x, double d)
|
||||||
{
|
{
|
||||||
union { double f; uint64_t i; } mem;
|
union { double f; uint64_t i; } mem;
|
||||||
mem.f = d;
|
mem.f = d;
|
||||||
unsigned char buf[9];
|
unsigned char buf[9];
|
||||||
buf[0] = 0xcb;
|
buf[0] = 0xcb;
|
||||||
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
||||||
// https://github.com/msgpack/msgpack-perl/pull/1
|
// https://github.com/msgpack/msgpack-perl/pull/1
|
||||||
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
||||||
#endif
|
#endif
|
||||||
_msgpack_store64(&buf[1], mem.i);
|
_msgpack_store64(&buf[1], mem.i);
|
||||||
msgpack_pack_append_buffer(x, buf, 9);
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -594,8 +594,8 @@ static inline int msgpack_pack_double(msgpack_packer* x, double d)
|
|||||||
|
|
||||||
static inline int msgpack_pack_nil(msgpack_packer* x)
|
static inline int msgpack_pack_nil(msgpack_packer* x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc0;
|
static const unsigned char d = 0xc0;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -605,14 +605,14 @@ static inline int msgpack_pack_nil(msgpack_packer* x)
|
|||||||
|
|
||||||
static inline int msgpack_pack_true(msgpack_packer* x)
|
static inline int msgpack_pack_true(msgpack_packer* x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc3;
|
static const unsigned char d = 0xc3;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_false(msgpack_packer* x)
|
static inline int msgpack_pack_false(msgpack_packer* x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc2;
|
static const unsigned char d = 0xc2;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -622,18 +622,18 @@ static inline int msgpack_pack_false(msgpack_packer* x)
|
|||||||
|
|
||||||
static inline int msgpack_pack_array(msgpack_packer* x, unsigned int n)
|
static inline int msgpack_pack_array(msgpack_packer* x, unsigned int n)
|
||||||
{
|
{
|
||||||
if(n < 16) {
|
if(n < 16) {
|
||||||
unsigned char d = 0x90 | n;
|
unsigned char d = 0x90 | n;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
} else if(n < 65536) {
|
} else if(n < 65536) {
|
||||||
unsigned char buf[3];
|
unsigned char buf[3];
|
||||||
buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
|
buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
} else {
|
} else {
|
||||||
unsigned char buf[5];
|
unsigned char buf[5];
|
||||||
buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
|
buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -643,18 +643,18 @@ static inline int msgpack_pack_array(msgpack_packer* x, unsigned int n)
|
|||||||
|
|
||||||
static inline int msgpack_pack_map(msgpack_packer* x, unsigned int n)
|
static inline int msgpack_pack_map(msgpack_packer* x, unsigned int n)
|
||||||
{
|
{
|
||||||
if(n < 16) {
|
if(n < 16) {
|
||||||
unsigned char d = 0x80 | n;
|
unsigned char d = 0x80 | n;
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
||||||
} else if(n < 65536) {
|
} else if(n < 65536) {
|
||||||
unsigned char buf[3];
|
unsigned char buf[3];
|
||||||
buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
|
buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
} else {
|
} else {
|
||||||
unsigned char buf[5];
|
unsigned char buf[5];
|
||||||
buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
|
buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -664,23 +664,23 @@ static inline int msgpack_pack_map(msgpack_packer* x, unsigned int n)
|
|||||||
|
|
||||||
static inline int msgpack_pack_raw(msgpack_packer* x, size_t l)
|
static inline int msgpack_pack_raw(msgpack_packer* x, size_t l)
|
||||||
{
|
{
|
||||||
if(l < 32) {
|
if(l < 32) {
|
||||||
unsigned char d = 0xa0 | (uint8_t)l;
|
unsigned char d = 0xa0 | (uint8_t)l;
|
||||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
||||||
} else if(l < 65536) {
|
} else if(l < 65536) {
|
||||||
unsigned char buf[3];
|
unsigned char buf[3];
|
||||||
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
|
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
} else {
|
} else {
|
||||||
unsigned char buf[5];
|
unsigned char buf[5];
|
||||||
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
|
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l)
|
static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l)
|
||||||
{
|
{
|
||||||
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
|
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef msgpack_pack_append_buffer
|
#undef msgpack_pack_append_buffer
|
||||||
@@ -698,4 +698,3 @@ static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t
|
|||||||
#undef msgpack_pack_real_int16
|
#undef msgpack_pack_real_int16
|
||||||
#undef msgpack_pack_real_int32
|
#undef msgpack_pack_real_int32
|
||||||
#undef msgpack_pack_real_int64
|
#undef msgpack_pack_real_int64
|
||||||
|
|
||||||
|
@@ -192,4 +192,3 @@ typedef unsigned int _msgpack_atomic_counter_t;
|
|||||||
|
|
||||||
|
|
||||||
#endif /* msgpack/sysdep.h */
|
#endif /* msgpack/sysdep.h */
|
||||||
|
|
||||||
|
@@ -35,53 +35,53 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CS_HEADER = 0x00, // nil
|
CS_HEADER = 0x00, // nil
|
||||||
|
|
||||||
//CS_ = 0x01,
|
//CS_ = 0x01,
|
||||||
//CS_ = 0x02, // false
|
//CS_ = 0x02, // false
|
||||||
//CS_ = 0x03, // true
|
//CS_ = 0x03, // true
|
||||||
|
|
||||||
//CS_ = 0x04,
|
//CS_ = 0x04,
|
||||||
//CS_ = 0x05,
|
//CS_ = 0x05,
|
||||||
//CS_ = 0x06,
|
//CS_ = 0x06,
|
||||||
//CS_ = 0x07,
|
//CS_ = 0x07,
|
||||||
|
|
||||||
//CS_ = 0x08,
|
//CS_ = 0x08,
|
||||||
//CS_ = 0x09,
|
//CS_ = 0x09,
|
||||||
CS_FLOAT = 0x0a,
|
CS_FLOAT = 0x0a,
|
||||||
CS_DOUBLE = 0x0b,
|
CS_DOUBLE = 0x0b,
|
||||||
CS_UINT_8 = 0x0c,
|
CS_UINT_8 = 0x0c,
|
||||||
CS_UINT_16 = 0x0d,
|
CS_UINT_16 = 0x0d,
|
||||||
CS_UINT_32 = 0x0e,
|
CS_UINT_32 = 0x0e,
|
||||||
CS_UINT_64 = 0x0f,
|
CS_UINT_64 = 0x0f,
|
||||||
CS_INT_8 = 0x10,
|
CS_INT_8 = 0x10,
|
||||||
CS_INT_16 = 0x11,
|
CS_INT_16 = 0x11,
|
||||||
CS_INT_32 = 0x12,
|
CS_INT_32 = 0x12,
|
||||||
CS_INT_64 = 0x13,
|
CS_INT_64 = 0x13,
|
||||||
|
|
||||||
//CS_ = 0x14,
|
//CS_ = 0x14,
|
||||||
//CS_ = 0x15,
|
//CS_ = 0x15,
|
||||||
//CS_BIG_INT_16 = 0x16,
|
//CS_BIG_INT_16 = 0x16,
|
||||||
//CS_BIG_INT_32 = 0x17,
|
//CS_BIG_INT_32 = 0x17,
|
||||||
//CS_BIG_FLOAT_16 = 0x18,
|
//CS_BIG_FLOAT_16 = 0x18,
|
||||||
//CS_BIG_FLOAT_32 = 0x19,
|
//CS_BIG_FLOAT_32 = 0x19,
|
||||||
CS_RAW_16 = 0x1a,
|
CS_RAW_16 = 0x1a,
|
||||||
CS_RAW_32 = 0x1b,
|
CS_RAW_32 = 0x1b,
|
||||||
CS_ARRAY_16 = 0x1c,
|
CS_ARRAY_16 = 0x1c,
|
||||||
CS_ARRAY_32 = 0x1d,
|
CS_ARRAY_32 = 0x1d,
|
||||||
CS_MAP_16 = 0x1e,
|
CS_MAP_16 = 0x1e,
|
||||||
CS_MAP_32 = 0x1f,
|
CS_MAP_32 = 0x1f,
|
||||||
|
|
||||||
//ACS_BIG_INT_VALUE,
|
//ACS_BIG_INT_VALUE,
|
||||||
//ACS_BIG_FLOAT_VALUE,
|
//ACS_BIG_FLOAT_VALUE,
|
||||||
ACS_RAW_VALUE,
|
ACS_RAW_VALUE,
|
||||||
} msgpack_unpack_state;
|
} msgpack_unpack_state;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CT_ARRAY_ITEM,
|
CT_ARRAY_ITEM,
|
||||||
CT_MAP_KEY,
|
CT_MAP_KEY,
|
||||||
CT_MAP_VALUE,
|
CT_MAP_VALUE,
|
||||||
} msgpack_container_type;
|
} msgpack_container_type;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,136 +23,136 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct unpack_stack {
|
typedef struct unpack_stack {
|
||||||
PyObject* obj;
|
PyObject* obj;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t count;
|
size_t count;
|
||||||
unsigned int ct;
|
unsigned int ct;
|
||||||
PyObject* map_key;
|
PyObject* map_key;
|
||||||
} unpack_stack;
|
} unpack_stack;
|
||||||
|
|
||||||
struct unpack_context {
|
struct unpack_context {
|
||||||
unpack_user user;
|
unpack_user user;
|
||||||
unsigned int cs;
|
unsigned int cs;
|
||||||
unsigned int trail;
|
unsigned int trail;
|
||||||
unsigned int top;
|
unsigned int top;
|
||||||
/*
|
/*
|
||||||
unpack_stack* stack;
|
unpack_stack* stack;
|
||||||
unsigned int stack_size;
|
unsigned int stack_size;
|
||||||
unpack_stack embed_stack[MSGPACK_EMBED_STACK_SIZE];
|
unpack_stack embed_stack[MSGPACK_EMBED_STACK_SIZE];
|
||||||
*/
|
*/
|
||||||
unpack_stack stack[MSGPACK_EMBED_STACK_SIZE];
|
unpack_stack stack[MSGPACK_EMBED_STACK_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline void unpack_init(unpack_context* ctx)
|
static inline void unpack_init(unpack_context* ctx)
|
||||||
{
|
{
|
||||||
ctx->cs = CS_HEADER;
|
ctx->cs = CS_HEADER;
|
||||||
ctx->trail = 0;
|
ctx->trail = 0;
|
||||||
ctx->top = 0;
|
ctx->top = 0;
|
||||||
/*
|
/*
|
||||||
ctx->stack = ctx->embed_stack;
|
ctx->stack = ctx->embed_stack;
|
||||||
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE;
|
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE;
|
||||||
*/
|
*/
|
||||||
ctx->stack[0].obj = unpack_callback_root(&ctx->user);
|
ctx->stack[0].obj = unpack_callback_root(&ctx->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static inline void unpack_destroy(unpack_context* ctx)
|
static inline void unpack_destroy(unpack_context* ctx)
|
||||||
{
|
{
|
||||||
if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) {
|
if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) {
|
||||||
free(ctx->stack);
|
free(ctx->stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline PyObject* unpack_data(unpack_context* ctx)
|
static inline PyObject* unpack_data(unpack_context* ctx)
|
||||||
{
|
{
|
||||||
return (ctx)->stack[0].obj;
|
return (ctx)->stack[0].obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <bool construct>
|
template <bool construct>
|
||||||
static inline int unpack_execute(unpack_context* ctx, const char* data, size_t len, size_t* off)
|
static inline int unpack_execute(unpack_context* ctx, const char* data, size_t len, size_t* off)
|
||||||
{
|
{
|
||||||
assert(len >= *off);
|
assert(len >= *off);
|
||||||
|
|
||||||
const unsigned char* p = (unsigned char*)data + *off;
|
const unsigned char* p = (unsigned char*)data + *off;
|
||||||
const unsigned char* const pe = (unsigned char*)data + len;
|
const unsigned char* const pe = (unsigned char*)data + len;
|
||||||
const void* n = NULL;
|
const void* n = NULL;
|
||||||
|
|
||||||
unsigned int trail = ctx->trail;
|
unsigned int trail = ctx->trail;
|
||||||
unsigned int cs = ctx->cs;
|
unsigned int cs = ctx->cs;
|
||||||
unsigned int top = ctx->top;
|
unsigned int top = ctx->top;
|
||||||
unpack_stack* stack = ctx->stack;
|
unpack_stack* stack = ctx->stack;
|
||||||
/*
|
/*
|
||||||
unsigned int stack_size = ctx->stack_size;
|
unsigned int stack_size = ctx->stack_size;
|
||||||
*/
|
*/
|
||||||
unpack_user* user = &ctx->user;
|
unpack_user* user = &ctx->user;
|
||||||
|
|
||||||
PyObject* obj;
|
PyObject* obj;
|
||||||
unpack_stack* c = NULL;
|
unpack_stack* c = NULL;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#define construct_cb(name) \
|
#define construct_cb(name) \
|
||||||
construct && unpack_callback ## name
|
construct && unpack_callback ## name
|
||||||
|
|
||||||
#define push_simple_value(func) \
|
#define push_simple_value(func) \
|
||||||
if(construct_cb(func)(user, &obj) < 0) { goto _failed; } \
|
if(construct_cb(func)(user, &obj) < 0) { goto _failed; } \
|
||||||
goto _push
|
goto _push
|
||||||
#define push_fixed_value(func, arg) \
|
#define push_fixed_value(func, arg) \
|
||||||
if(construct_cb(func)(user, arg, &obj) < 0) { goto _failed; } \
|
if(construct_cb(func)(user, arg, &obj) < 0) { goto _failed; } \
|
||||||
goto _push
|
goto _push
|
||||||
#define push_variable_value(func, base, pos, len) \
|
#define push_variable_value(func, base, pos, len) \
|
||||||
if(construct_cb(func)(user, \
|
if(construct_cb(func)(user, \
|
||||||
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
||||||
goto _push
|
goto _push
|
||||||
|
|
||||||
#define again_fixed_trail(_cs, trail_len) \
|
#define again_fixed_trail(_cs, trail_len) \
|
||||||
trail = trail_len; \
|
trail = trail_len; \
|
||||||
cs = _cs; \
|
cs = _cs; \
|
||||||
goto _fixed_trail_again
|
goto _fixed_trail_again
|
||||||
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
|
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
|
||||||
trail = trail_len; \
|
trail = trail_len; \
|
||||||
if(trail == 0) { goto ifzero; } \
|
if(trail == 0) { goto ifzero; } \
|
||||||
cs = _cs; \
|
cs = _cs; \
|
||||||
goto _fixed_trail_again
|
goto _fixed_trail_again
|
||||||
|
|
||||||
#define start_container(func, count_, ct_) \
|
#define start_container(func, count_, ct_) \
|
||||||
if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
|
if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
|
||||||
if(construct_cb(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
if(construct_cb(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
||||||
if((count_) == 0) { obj = stack[top].obj; \
|
if((count_) == 0) { obj = stack[top].obj; \
|
||||||
if (construct_cb(func##_end)(user, &obj) < 0) { goto _failed; } \
|
if (construct_cb(func##_end)(user, &obj) < 0) { goto _failed; } \
|
||||||
goto _push; } \
|
goto _push; } \
|
||||||
stack[top].ct = ct_; \
|
stack[top].ct = ct_; \
|
||||||
stack[top].size = count_; \
|
stack[top].size = count_; \
|
||||||
stack[top].count = 0; \
|
stack[top].count = 0; \
|
||||||
++top; \
|
++top; \
|
||||||
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
||||||
/*printf("stack push %d\n", top);*/ \
|
/*printf("stack push %d\n", top);*/ \
|
||||||
/* FIXME \
|
/* FIXME \
|
||||||
if(top >= stack_size) { \
|
if(top >= stack_size) { \
|
||||||
if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
|
if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
|
||||||
size_t csize = sizeof(unpack_stack) * MSGPACK_EMBED_STACK_SIZE; \
|
size_t csize = sizeof(unpack_stack) * MSGPACK_EMBED_STACK_SIZE; \
|
||||||
size_t nsize = csize * 2; \
|
size_t nsize = csize * 2; \
|
||||||
unpack_stack* tmp = (unpack_stack*)malloc(nsize); \
|
unpack_stack* tmp = (unpack_stack*)malloc(nsize); \
|
||||||
if(tmp == NULL) { goto _failed; } \
|
if(tmp == NULL) { goto _failed; } \
|
||||||
memcpy(tmp, ctx->stack, csize); \
|
memcpy(tmp, ctx->stack, csize); \
|
||||||
ctx->stack = stack = tmp; \
|
ctx->stack = stack = tmp; \
|
||||||
ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
|
ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
|
||||||
} else { \
|
} else { \
|
||||||
size_t nsize = sizeof(unpack_stack) * ctx->stack_size * 2; \
|
size_t nsize = sizeof(unpack_stack) * ctx->stack_size * 2; \
|
||||||
unpack_stack* tmp = (unpack_stack*)realloc(ctx->stack, nsize); \
|
unpack_stack* tmp = (unpack_stack*)realloc(ctx->stack, nsize); \
|
||||||
if(tmp == NULL) { goto _failed; } \
|
if(tmp == NULL) { goto _failed; } \
|
||||||
ctx->stack = stack = tmp; \
|
ctx->stack = stack = tmp; \
|
||||||
ctx->stack_size = stack_size = stack_size * 2; \
|
ctx->stack_size = stack_size = stack_size * 2; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
*/ \
|
*/ \
|
||||||
goto _header_again
|
goto _header_again
|
||||||
|
|
||||||
#define NEXT_CS(p) \
|
#define NEXT_CS(p) \
|
||||||
((unsigned int)*p & 0x1f)
|
((unsigned int)*p & 0x1f)
|
||||||
|
|
||||||
#ifdef USE_CASE_RANGE
|
#ifdef USE_CASE_RANGE
|
||||||
#define SWITCH_RANGE_BEGIN switch(*p) {
|
#define SWITCH_RANGE_BEGIN switch(*p) {
|
||||||
@@ -166,221 +166,221 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, size_t l
|
|||||||
#define SWITCH_RANGE_END } }
|
#define SWITCH_RANGE_END } }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(p == pe) { goto _out; }
|
if(p == pe) { goto _out; }
|
||||||
do {
|
do {
|
||||||
switch(cs) {
|
switch(cs) {
|
||||||
case CS_HEADER:
|
case CS_HEADER:
|
||||||
SWITCH_RANGE_BEGIN
|
SWITCH_RANGE_BEGIN
|
||||||
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
|
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
|
||||||
push_fixed_value(_uint8, *(uint8_t*)p);
|
push_fixed_value(_uint8, *(uint8_t*)p);
|
||||||
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
|
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
|
||||||
push_fixed_value(_int8, *(int8_t*)p);
|
push_fixed_value(_int8, *(int8_t*)p);
|
||||||
SWITCH_RANGE(0xc0, 0xdf) // Variable
|
SWITCH_RANGE(0xc0, 0xdf) // Variable
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case 0xc0: // nil
|
case 0xc0: // nil
|
||||||
push_simple_value(_nil);
|
push_simple_value(_nil);
|
||||||
//case 0xc1: // string
|
//case 0xc1: // string
|
||||||
// again_terminal_trail(NEXT_CS(p), p+1);
|
// again_terminal_trail(NEXT_CS(p), p+1);
|
||||||
case 0xc2: // false
|
case 0xc2: // false
|
||||||
push_simple_value(_false);
|
push_simple_value(_false);
|
||||||
case 0xc3: // true
|
case 0xc3: // true
|
||||||
push_simple_value(_true);
|
push_simple_value(_true);
|
||||||
//case 0xc4:
|
//case 0xc4:
|
||||||
//case 0xc5:
|
//case 0xc5:
|
||||||
//case 0xc6:
|
//case 0xc6:
|
||||||
//case 0xc7:
|
//case 0xc7:
|
||||||
//case 0xc8:
|
//case 0xc8:
|
||||||
//case 0xc9:
|
//case 0xc9:
|
||||||
case 0xca: // float
|
case 0xca: // float
|
||||||
case 0xcb: // double
|
case 0xcb: // double
|
||||||
case 0xcc: // unsigned int 8
|
case 0xcc: // unsigned int 8
|
||||||
case 0xcd: // unsigned int 16
|
case 0xcd: // unsigned int 16
|
||||||
case 0xce: // unsigned int 32
|
case 0xce: // unsigned int 32
|
||||||
case 0xcf: // unsigned int 64
|
case 0xcf: // unsigned int 64
|
||||||
case 0xd0: // signed int 8
|
case 0xd0: // signed int 8
|
||||||
case 0xd1: // signed int 16
|
case 0xd1: // signed int 16
|
||||||
case 0xd2: // signed int 32
|
case 0xd2: // signed int 32
|
||||||
case 0xd3: // signed int 64
|
case 0xd3: // signed int 64
|
||||||
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
|
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
|
||||||
//case 0xd4:
|
//case 0xd4:
|
||||||
//case 0xd5:
|
//case 0xd5:
|
||||||
//case 0xd6: // big integer 16
|
//case 0xd6: // big integer 16
|
||||||
//case 0xd7: // big integer 32
|
//case 0xd7: // big integer 32
|
||||||
//case 0xd8: // big float 16
|
//case 0xd8: // big float 16
|
||||||
//case 0xd9: // big float 32
|
//case 0xd9: // big float 32
|
||||||
case 0xda: // raw 16
|
case 0xda: // raw 16
|
||||||
case 0xdb: // raw 32
|
case 0xdb: // raw 32
|
||||||
case 0xdc: // array 16
|
case 0xdc: // array 16
|
||||||
case 0xdd: // array 32
|
case 0xdd: // array 32
|
||||||
case 0xde: // map 16
|
case 0xde: // map 16
|
||||||
case 0xdf: // map 32
|
case 0xdf: // map 32
|
||||||
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
|
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
|
||||||
default:
|
default:
|
||||||
goto _failed;
|
goto _failed;
|
||||||
}
|
}
|
||||||
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
|
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
|
||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
||||||
SWITCH_RANGE(0x90, 0x9f) // FixArray
|
SWITCH_RANGE(0x90, 0x9f) // FixArray
|
||||||
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
||||||
SWITCH_RANGE(0x80, 0x8f) // FixMap
|
SWITCH_RANGE(0x80, 0x8f) // FixMap
|
||||||
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
||||||
|
|
||||||
SWITCH_RANGE_DEFAULT
|
SWITCH_RANGE_DEFAULT
|
||||||
goto _failed;
|
goto _failed;
|
||||||
SWITCH_RANGE_END
|
SWITCH_RANGE_END
|
||||||
// end CS_HEADER
|
// end CS_HEADER
|
||||||
|
|
||||||
|
|
||||||
_fixed_trail_again:
|
_fixed_trail_again:
|
||||||
++p;
|
++p;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if((size_t)(pe - p) < trail) { goto _out; }
|
if((size_t)(pe - p) < trail) { goto _out; }
|
||||||
n = p; p += trail - 1;
|
n = p; p += trail - 1;
|
||||||
switch(cs) {
|
switch(cs) {
|
||||||
//case CS_
|
//case CS_
|
||||||
//case CS_
|
//case CS_
|
||||||
case CS_FLOAT: {
|
case CS_FLOAT: {
|
||||||
union { uint32_t i; float f; } mem;
|
union { uint32_t i; float f; } mem;
|
||||||
mem.i = _msgpack_load32(uint32_t,n);
|
mem.i = _msgpack_load32(uint32_t,n);
|
||||||
push_fixed_value(_float, mem.f); }
|
push_fixed_value(_float, mem.f); }
|
||||||
case CS_DOUBLE: {
|
case CS_DOUBLE: {
|
||||||
union { uint64_t i; double f; } mem;
|
union { uint64_t i; double f; } mem;
|
||||||
mem.i = _msgpack_load64(uint64_t,n);
|
mem.i = _msgpack_load64(uint64_t,n);
|
||||||
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
||||||
// https://github.com/msgpack/msgpack-perl/pull/1
|
// https://github.com/msgpack/msgpack-perl/pull/1
|
||||||
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
||||||
#endif
|
#endif
|
||||||
push_fixed_value(_double, mem.f); }
|
push_fixed_value(_double, mem.f); }
|
||||||
case CS_UINT_8:
|
case CS_UINT_8:
|
||||||
push_fixed_value(_uint8, *(uint8_t*)n);
|
push_fixed_value(_uint8, *(uint8_t*)n);
|
||||||
case CS_UINT_16:
|
case CS_UINT_16:
|
||||||
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
|
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
|
||||||
case CS_UINT_32:
|
case CS_UINT_32:
|
||||||
push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
|
push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
|
||||||
case CS_UINT_64:
|
case CS_UINT_64:
|
||||||
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
|
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
|
||||||
|
|
||||||
case CS_INT_8:
|
case CS_INT_8:
|
||||||
push_fixed_value(_int8, *(int8_t*)n);
|
push_fixed_value(_int8, *(int8_t*)n);
|
||||||
case CS_INT_16:
|
case CS_INT_16:
|
||||||
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
|
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
|
||||||
case CS_INT_32:
|
case CS_INT_32:
|
||||||
push_fixed_value(_int32, _msgpack_load32(int32_t,n));
|
push_fixed_value(_int32, _msgpack_load32(int32_t,n));
|
||||||
case CS_INT_64:
|
case CS_INT_64:
|
||||||
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
|
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
|
||||||
|
|
||||||
//case CS_
|
//case CS_
|
||||||
//case CS_
|
//case CS_
|
||||||
//case CS_BIG_INT_16:
|
//case CS_BIG_INT_16:
|
||||||
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
|
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
|
||||||
//case CS_BIG_INT_32:
|
//case CS_BIG_INT_32:
|
||||||
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
|
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
|
||||||
//case ACS_BIG_INT_VALUE:
|
//case ACS_BIG_INT_VALUE:
|
||||||
//_big_int_zero:
|
//_big_int_zero:
|
||||||
// // FIXME
|
// // FIXME
|
||||||
// push_variable_value(_big_int, data, n, trail);
|
// push_variable_value(_big_int, data, n, trail);
|
||||||
|
|
||||||
//case CS_BIG_FLOAT_16:
|
//case CS_BIG_FLOAT_16:
|
||||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
|
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
|
||||||
//case CS_BIG_FLOAT_32:
|
//case CS_BIG_FLOAT_32:
|
||||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
|
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
|
||||||
//case ACS_BIG_FLOAT_VALUE:
|
//case ACS_BIG_FLOAT_VALUE:
|
||||||
//_big_float_zero:
|
//_big_float_zero:
|
||||||
// // FIXME
|
// // FIXME
|
||||||
// push_variable_value(_big_float, data, n, trail);
|
// push_variable_value(_big_float, data, n, trail);
|
||||||
|
|
||||||
case CS_RAW_16:
|
case CS_RAW_16:
|
||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
|
||||||
case CS_RAW_32:
|
case CS_RAW_32:
|
||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
|
||||||
case ACS_RAW_VALUE:
|
case ACS_RAW_VALUE:
|
||||||
_raw_zero:
|
_raw_zero:
|
||||||
push_variable_value(_raw, data, n, trail);
|
push_variable_value(_raw, data, n, trail);
|
||||||
|
|
||||||
case CS_ARRAY_16:
|
case CS_ARRAY_16:
|
||||||
start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
|
start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
|
||||||
case CS_ARRAY_32:
|
case CS_ARRAY_32:
|
||||||
/* FIXME security guard */
|
/* FIXME security guard */
|
||||||
start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
|
start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
|
||||||
|
|
||||||
case CS_MAP_16:
|
case CS_MAP_16:
|
||||||
start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
|
start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
|
||||||
case CS_MAP_32:
|
case CS_MAP_32:
|
||||||
/* FIXME security guard */
|
/* FIXME security guard */
|
||||||
start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
|
start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto _failed;
|
goto _failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_push:
|
_push:
|
||||||
if(top == 0) { goto _finish; }
|
if(top == 0) { goto _finish; }
|
||||||
c = &stack[top-1];
|
c = &stack[top-1];
|
||||||
switch(c->ct) {
|
switch(c->ct) {
|
||||||
case CT_ARRAY_ITEM:
|
case CT_ARRAY_ITEM:
|
||||||
if(construct_cb(_array_item)(user, c->count, &c->obj, obj) < 0) { goto _failed; }
|
if(construct_cb(_array_item)(user, c->count, &c->obj, obj) < 0) { goto _failed; }
|
||||||
if(++c->count == c->size) {
|
if(++c->count == c->size) {
|
||||||
obj = c->obj;
|
obj = c->obj;
|
||||||
if (construct_cb(_array_end)(user, &obj) < 0) { goto _failed; }
|
if (construct_cb(_array_end)(user, &obj) < 0) { goto _failed; }
|
||||||
--top;
|
--top;
|
||||||
/*printf("stack pop %d\n", top);*/
|
/*printf("stack pop %d\n", top);*/
|
||||||
goto _push;
|
goto _push;
|
||||||
}
|
}
|
||||||
goto _header_again;
|
goto _header_again;
|
||||||
case CT_MAP_KEY:
|
case CT_MAP_KEY:
|
||||||
c->map_key = obj;
|
c->map_key = obj;
|
||||||
c->ct = CT_MAP_VALUE;
|
c->ct = CT_MAP_VALUE;
|
||||||
goto _header_again;
|
goto _header_again;
|
||||||
case CT_MAP_VALUE:
|
case CT_MAP_VALUE:
|
||||||
if(construct_cb(_map_item)(user, c->count, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
if(construct_cb(_map_item)(user, c->count, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
||||||
if(++c->count == c->size) {
|
if(++c->count == c->size) {
|
||||||
obj = c->obj;
|
obj = c->obj;
|
||||||
if (construct_cb(_map_end)(user, &obj) < 0) { goto _failed; }
|
if (construct_cb(_map_end)(user, &obj) < 0) { goto _failed; }
|
||||||
--top;
|
--top;
|
||||||
/*printf("stack pop %d\n", top);*/
|
/*printf("stack pop %d\n", top);*/
|
||||||
goto _push;
|
goto _push;
|
||||||
}
|
}
|
||||||
c->ct = CT_MAP_KEY;
|
c->ct = CT_MAP_KEY;
|
||||||
goto _header_again;
|
goto _header_again;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto _failed;
|
goto _failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
_header_again:
|
_header_again:
|
||||||
cs = CS_HEADER;
|
cs = CS_HEADER;
|
||||||
++p;
|
++p;
|
||||||
} while(p != pe);
|
} while(p != pe);
|
||||||
goto _out;
|
goto _out;
|
||||||
|
|
||||||
|
|
||||||
_finish:
|
_finish:
|
||||||
if (!construct)
|
if (!construct)
|
||||||
unpack_callback_nil(user, &obj);
|
unpack_callback_nil(user, &obj);
|
||||||
stack[0].obj = obj;
|
stack[0].obj = obj;
|
||||||
++p;
|
++p;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
/*printf("-- finish --\n"); */
|
/*printf("-- finish --\n"); */
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
||||||
_failed:
|
_failed:
|
||||||
/*printf("** FAILED **\n"); */
|
/*printf("** FAILED **\n"); */
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
||||||
_out:
|
_out:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
ctx->cs = cs;
|
ctx->cs = cs;
|
||||||
ctx->trail = trail;
|
ctx->trail = trail;
|
||||||
ctx->top = top;
|
ctx->top = top;
|
||||||
*off = p - (const unsigned char*)data;
|
*off = p - (const unsigned char*)data;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#undef construct_cb
|
#undef construct_cb
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,53 +398,53 @@ _end:
|
|||||||
template <unsigned int fixed_offset, unsigned int var_offset>
|
template <unsigned int fixed_offset, unsigned int var_offset>
|
||||||
static inline int unpack_container_header(unpack_context* ctx, const char* data, size_t len, size_t* off)
|
static inline int unpack_container_header(unpack_context* ctx, const char* data, size_t len, size_t* off)
|
||||||
{
|
{
|
||||||
assert(len >= *off);
|
assert(len >= *off);
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
const unsigned char *const p = (unsigned char*)data + *off;
|
const unsigned char *const p = (unsigned char*)data + *off;
|
||||||
|
|
||||||
#define inc_offset(inc) \
|
#define inc_offset(inc) \
|
||||||
if (len - *off < inc) \
|
if (len - *off < inc) \
|
||||||
return 0; \
|
return 0; \
|
||||||
*off += inc;
|
*off += inc;
|
||||||
|
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case var_offset:
|
case var_offset:
|
||||||
inc_offset(3);
|
inc_offset(3);
|
||||||
size = _msgpack_load16(uint16_t, p + 1);
|
size = _msgpack_load16(uint16_t, p + 1);
|
||||||
break;
|
break;
|
||||||
case var_offset + 1:
|
case var_offset + 1:
|
||||||
inc_offset(5);
|
inc_offset(5);
|
||||||
size = _msgpack_load32(uint32_t, p + 1);
|
size = _msgpack_load32(uint32_t, p + 1);
|
||||||
break;
|
break;
|
||||||
#ifdef USE_CASE_RANGE
|
#ifdef USE_CASE_RANGE
|
||||||
case fixed_offset + 0x0 ... fixed_offset + 0xf:
|
case fixed_offset + 0x0 ... fixed_offset + 0xf:
|
||||||
#else
|
#else
|
||||||
case fixed_offset + 0x0:
|
case fixed_offset + 0x0:
|
||||||
case fixed_offset + 0x1:
|
case fixed_offset + 0x1:
|
||||||
case fixed_offset + 0x2:
|
case fixed_offset + 0x2:
|
||||||
case fixed_offset + 0x3:
|
case fixed_offset + 0x3:
|
||||||
case fixed_offset + 0x4:
|
case fixed_offset + 0x4:
|
||||||
case fixed_offset + 0x5:
|
case fixed_offset + 0x5:
|
||||||
case fixed_offset + 0x6:
|
case fixed_offset + 0x6:
|
||||||
case fixed_offset + 0x7:
|
case fixed_offset + 0x7:
|
||||||
case fixed_offset + 0x8:
|
case fixed_offset + 0x8:
|
||||||
case fixed_offset + 0x9:
|
case fixed_offset + 0x9:
|
||||||
case fixed_offset + 0xa:
|
case fixed_offset + 0xa:
|
||||||
case fixed_offset + 0xb:
|
case fixed_offset + 0xb:
|
||||||
case fixed_offset + 0xc:
|
case fixed_offset + 0xc:
|
||||||
case fixed_offset + 0xd:
|
case fixed_offset + 0xd:
|
||||||
case fixed_offset + 0xe:
|
case fixed_offset + 0xe:
|
||||||
case fixed_offset + 0xf:
|
case fixed_offset + 0xf:
|
||||||
#endif
|
#endif
|
||||||
++*off;
|
++*off;
|
||||||
size = ((unsigned int)*p) & 0x0f;
|
size = ((unsigned int)*p) & 0x0f;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream");
|
PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
unpack_callback_uint32(&ctx->user, size, &ctx->stack[0].obj);
|
unpack_callback_uint32(&ctx->user, size, &ctx->stack[0].obj);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef SWITCH_RANGE_BEGIN
|
#undef SWITCH_RANGE_BEGIN
|
||||||
@@ -459,4 +459,4 @@ static const execute_fn read_map_header = &unpack_container_header<0x80, 0xde>;
|
|||||||
|
|
||||||
#undef NEXT_CS
|
#undef NEXT_CS
|
||||||
|
|
||||||
/* vim: set ts=4 sw=4 noexpandtab */
|
/* vim: set ts=4 sw=4 sts=4 expandtab */
|
||||||
|
Reference in New Issue
Block a user