mirror of
https://github.com/msgpack/msgpack-c
synced 2026-06-08 16:11:40 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bd53f018f | |||
| 840388720e | |||
| c612a177cc | |||
| 44cdc5f976 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
AC_INIT(msgpack/unpack_template.h)
|
||||
AC_CONFIG_AUX_DIR(ac)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.3.0)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.3.1)
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_SUBST(CFLAGS)
|
||||
|
||||
+132
-72
@@ -24,29 +24,79 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#define STORE_BE16(d) \
|
||||
((char*)&d)[1], ((char*)&d)[0]
|
||||
#define STORE8_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE_BE32(d) \
|
||||
((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0]
|
||||
|
||||
#define STORE_BE64(d) \
|
||||
((char*)&d)[7], ((char*)&d)[6], ((char*)&d)[5], ((char*)&d)[4], \
|
||||
((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0]
|
||||
#define STORE16_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE16_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE32_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE64_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE64(d) \
|
||||
((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#elif __BIG_ENDIAN__
|
||||
|
||||
#define STORE_BE16(d) \
|
||||
((char*)&d)[0], ((char*)&d)[1]
|
||||
#define STORE8_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE_BE32(d) \
|
||||
((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3]
|
||||
|
||||
#define STORE_BE64(d) \
|
||||
((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3], \
|
||||
((char*)&d)[4], ((char*)&d)[5], ((char*)&d)[6], ((char*)&d)[7]
|
||||
#define STORE16_BE8(d) \
|
||||
((uint8_t*)&d)[1]
|
||||
|
||||
#define STORE16_BE16(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1]
|
||||
|
||||
|
||||
#define STORE32_BE8(d) \
|
||||
((uint8_t*)&d)[3]
|
||||
|
||||
#define STORE32_BE16(d) \
|
||||
((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
||||
|
||||
#define STORE32_BE32(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
||||
|
||||
|
||||
#define STORE64_BE8(d) \
|
||||
((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE16(d) \
|
||||
((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE32(d) \
|
||||
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE64(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3], \
|
||||
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#endif
|
||||
|
||||
@@ -71,10 +121,10 @@
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} while(0)
|
||||
@@ -83,14 +133,14 @@ do { \
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
||||
} else if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} while(0)
|
||||
@@ -100,20 +150,20 @@ do { \
|
||||
if(d < (1<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
@@ -124,24 +174,24 @@ do { \
|
||||
if(d < (1ULL<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1ULL<<16)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else if(d < (1ULL<<32)) { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* signed 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE_BE64(d)}; \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
@@ -151,11 +201,11 @@ do { \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, d}; \
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@@ -164,24 +214,24 @@ do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} \
|
||||
@@ -192,32 +242,32 @@ do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<15)) { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
@@ -229,46 +279,46 @@ do { \
|
||||
if(d < -(1LL<<15)) { \
|
||||
if(d < -(1LL<<31)) { \
|
||||
/* signed 64 */ \
|
||||
const unsigned char buf[9] = {0xd3, STORE_BE64(d)}; \
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} else { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
||||
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1LL<<16)) { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1LL<<32)) { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* unsigned 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE_BE64(d)}; \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
@@ -280,49 +330,49 @@ do { \
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||
{
|
||||
const unsigned char buf[2] = {0xcc, d};
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
||||
{
|
||||
const unsigned char buf[2] = {0xd0, d};
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
@@ -554,7 +604,7 @@ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
||||
{
|
||||
union { char buf[4]; uint32_t num; } f;
|
||||
*((float*)&f.buf) = d; // FIXME
|
||||
const unsigned char buf[5] = {0xca, STORE_BE32(f.num)};
|
||||
const unsigned char buf[5] = {0xca, STORE32_BE32(f.num)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
@@ -562,7 +612,7 @@ msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
||||
{
|
||||
union { char buf[8]; uint64_t num; } f;
|
||||
*((double*)&f.buf) = d; // FIXME
|
||||
const unsigned char buf[9] = {0xcb, STORE_BE64(f.num)};
|
||||
const unsigned char buf[9] = {0xcb, STORE64_BE64(f.num)};
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
@@ -606,11 +656,11 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
} else if(n < 65536) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xdc, STORE_BE16(d)};
|
||||
unsigned char buf[3] = {0xdc, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdd, STORE_BE32(d)};
|
||||
unsigned char buf[5] = {0xdd, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -624,14 +674,14 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
||||
{
|
||||
if(n < 16) {
|
||||
unsigned char d = 0x80 | n;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
|
||||
} else if(n < 65536) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xde, STORE_BE16(d)};
|
||||
unsigned char buf[3] = {0xde, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdf, STORE_BE32(d)};
|
||||
unsigned char buf[5] = {0xdf, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -645,14 +695,14 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
|
||||
{
|
||||
if(l < 32) {
|
||||
unsigned char d = 0xa0 | l;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
|
||||
} else if(l < 65536) {
|
||||
uint16_t d = (uint16_t)l;
|
||||
unsigned char buf[3] = {0xda, STORE_BE16(d)};
|
||||
unsigned char buf[3] = {0xda, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)l;
|
||||
unsigned char buf[5] = {0xdb, STORE_BE32(d)};
|
||||
unsigned char buf[5] = {0xdb, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -666,9 +716,19 @@ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l
|
||||
#undef msgpack_pack_user
|
||||
#undef msgpack_pack_append_buffer
|
||||
|
||||
#undef STORE_BE16
|
||||
#undef STORE_BE32
|
||||
#undef STORE_BE64
|
||||
#undef STORE8_BE8
|
||||
|
||||
#undef STORE16_BE8
|
||||
#undef STORE16_BE16
|
||||
|
||||
#undef STORE32_BE8
|
||||
#undef STORE32_BE16
|
||||
#undef STORE32_BE32
|
||||
|
||||
#undef STORE64_BE8
|
||||
#undef STORE64_BE16
|
||||
#undef STORE64_BE32
|
||||
#undef STORE64_BE64
|
||||
|
||||
#undef msgpack_pack_real_uint8
|
||||
#undef msgpack_pack_real_uint16
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ DESCRIPTION = "Binary-based efficient data interchange format."
|
||||
RUBYFORGE_PROJECT = "msgpack"
|
||||
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
||||
BIN_FILES = %w( )
|
||||
VERS = "0.3.0"
|
||||
VERS = "0.3.1"
|
||||
|
||||
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
||||
REV = nil
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.platform = Gem::Platform::CURRENT
|
||||
s.name = "msgpack"
|
||||
s.version = "0.3.0"
|
||||
s.version = "0.3.1"
|
||||
s.summary = "MessagePack"
|
||||
s.author = "FURUHASHI Sadayuki"
|
||||
s.email = "frsyuki@users.sourceforge.jp"
|
||||
|
||||
+76
-2
@@ -113,6 +113,80 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
||||
#check_array 5, (1<<32)-1 # memory error
|
||||
end
|
||||
|
||||
it "nil" do
|
||||
match nil, "\xc0"
|
||||
end
|
||||
|
||||
it "false" do
|
||||
match false, "\xc2"
|
||||
end
|
||||
|
||||
it "true" do
|
||||
match true, "\xc3"
|
||||
end
|
||||
|
||||
it "0" do
|
||||
match 0, "\x00"
|
||||
end
|
||||
|
||||
it "127" do
|
||||
match 127, "\x7f"
|
||||
end
|
||||
|
||||
it "128" do
|
||||
match 128, "\xcc\x80"
|
||||
end
|
||||
|
||||
it "256" do
|
||||
match 256, "\xcd\x01\x00"
|
||||
end
|
||||
|
||||
it "-1" do
|
||||
match -1, "\xff"
|
||||
end
|
||||
|
||||
it "-33" do
|
||||
match -33, "\xd0\xdf"
|
||||
end
|
||||
|
||||
it "-129" do
|
||||
match -129, "\xd1\xff\x7f"
|
||||
end
|
||||
|
||||
it "{1=>1}" do
|
||||
match ({1=>1}), "\x81\x01\x01"
|
||||
end
|
||||
|
||||
it "1.0" do
|
||||
match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
|
||||
end
|
||||
|
||||
it "[]" do
|
||||
match [], "\x90"
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 14]" do
|
||||
match (0..14).to_a, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 15]" do
|
||||
match (0..15).to_a, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
end
|
||||
|
||||
it "{}" do
|
||||
match ({}), "\x80"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 14=>14}" do
|
||||
a = (0..14).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 15=>15}" do
|
||||
a = (0..15).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
|
||||
end
|
||||
|
||||
# it "fixmap" do
|
||||
# check_map 1, 0
|
||||
# check_map 1, (1<<4)-1
|
||||
@@ -143,8 +217,8 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
||||
check num+overhead, Array.new(num)
|
||||
end
|
||||
|
||||
def check_map(overhead, num)
|
||||
# FIXME
|
||||
def match(obj, buf)
|
||||
assert_equal(obj.to_msgpack, buf)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user