Changeset 18599
- Timestamp:
- 09/02/08 00:08:33 (5 years ago)
- Location:
- lang/c/msgpack/trunk
- Files:
-
- 10 added
- 4 removed
- 3 modified
-
cpp/Makefile (added)
-
cpp/msgpack (added)
-
cpp/object.hpp (added)
-
cpp/test.cpp (added)
-
cpp/unpack.cc (deleted)
-
cpp/unpack.cpp (added)
-
cpp/unpack.h (deleted)
-
cpp/unpack.hpp (added)
-
cpp/unpack_context.h (deleted)
-
cpp/unpack_context.hpp (added)
-
cpp/unpack_inline.cpp (added)
-
cpp/zone.cpp (added)
-
cpp/zone.hpp.erb (added)
-
msgpack/pack/inline_context.h (deleted)
-
msgpack/pack/inline_impl.h (modified) (18 diffs)
-
msgpack/unpack/inline_context.h (modified) (2 diffs)
-
msgpack/unpack/inline_impl.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/msgpack/trunk/msgpack/pack/inline_impl.h
r17708 r18599 24 24 #ifdef __LITTLE_ENDIAN__ 25 25 26 #define STORE_ 16(d) \26 #define STORE_BE16(d) \ 27 27 ((char*)&d)[1], ((char*)&d)[0] 28 28 29 #define STORE_ 32(d) \29 #define STORE_BE32(d) \ 30 30 ((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0] 31 31 32 #define STORE_ 64(d) \32 #define STORE_BE64(d) \ 33 33 ((char*)&d)[7], ((char*)&d)[6], ((char*)&d)[5], ((char*)&d)[4], \ 34 34 ((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0] … … 36 36 #elif __BIG_ENDIAN__ 37 37 38 #define STORE_ 16(d) \39 ((char*)&d)[ 2], ((char*)&d)[3]40 41 #define STORE_ 32(d) \38 #define STORE_BE16(d) \ 39 ((char*)&d)[0], ((char*)&d)[1] 40 41 #define STORE_BE32(d) \ 42 42 ((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3] 43 43 44 #define STORE_ 32(d) \44 #define STORE_BE64(d) \ 45 45 ((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3], \ 46 46 ((char*)&d)[4], ((char*)&d)[5], ((char*)&d)[6], ((char*)&d)[7] … … 58 58 if(d < -32) { 59 59 if(d < -32768) { // signed 32 60 const unsigned char buf[5] = {0xd2, STORE_ 32(d)};60 const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; 61 61 msgpack_pack_append_buffer(x, buf, 5); 62 62 } else if(d < -128) { // signed 16 63 const unsigned char buf[3] = {0xd1, STORE_ 16(d)};63 const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; 64 64 msgpack_pack_append_buffer(x, buf, 3); 65 65 } else { // signed 8 … … 76 76 } else if(d < 65536) { 77 77 // unsigned 16 78 const unsigned char buf[3] = {0xcd, STORE_ 16(d)};78 const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; 79 79 msgpack_pack_append_buffer(x, buf, 3); 80 80 } else { 81 81 // unsigned 32 82 const unsigned char buf[5] = {0xce, STORE_ 32(d)};82 const unsigned char buf[5] = {0xce, STORE_BE32(d)}; 83 83 msgpack_pack_append_buffer(x, buf, 5); 84 84 } … … 98 98 } else if(d < 65536) { 99 99 // unsigned 16 100 const unsigned char buf[3] = {0xcd, STORE_ 16(d)};100 const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; 101 101 msgpack_pack_append_buffer(x, buf, 3); 102 102 } else { 103 103 // unsigned 32 104 const unsigned char buf[5] = {0xce, STORE_ 32(d)};104 const unsigned char buf[5] = {0xce, STORE_BE32(d)}; 105 105 msgpack_pack_append_buffer(x, buf, 5); 106 106 } … … 119 119 inline void msgpack_pack_unsigned_int_16(msgpack_pack_context x, uint16_t d) 120 120 { 121 const unsigned char buf[3] = {0xcd, STORE_ 16(d)};121 const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; 122 122 msgpack_pack_append_buffer(x, buf, 3); 123 123 } … … 125 125 inline void msgpack_pack_unsigned_int_32(msgpack_pack_context x, uint32_t d) 126 126 { 127 const unsigned char buf[5] = {0xce, STORE_ 32(d)};127 const unsigned char buf[5] = {0xce, STORE_BE32(d)}; 128 128 msgpack_pack_append_buffer(x, buf, 5); 129 129 } … … 131 131 inline void msgpack_pack_unsigned_int_64(msgpack_pack_context x, uint64_t d) 132 132 { 133 // FIXME 134 const unsigned char buf[9] = {0xcf, STORE_ 64(d)};133 // FIXME optimization 134 const unsigned char buf[9] = {0xcf, STORE_BE64(d)}; 135 135 msgpack_pack_append_buffer(x, buf, 9); 136 136 } … … 150 150 inline void msgpack_pack_signed_int_16(msgpack_pack_context x, int16_t d) 151 151 { 152 const unsigned char buf[3] = {0xd1, STORE_ 16(d)};152 const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; 153 153 msgpack_pack_append_buffer(x, buf, 3); 154 154 } … … 156 156 inline void msgpack_pack_signed_int_32(msgpack_pack_context x, int32_t d) 157 157 { 158 const unsigned char buf[5] = {0xd2, STORE_ 32(d)};158 const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; 159 159 msgpack_pack_append_buffer(x, buf, 5); 160 160 } … … 162 162 inline void msgpack_pack_signed_int_64(msgpack_pack_context x, int64_t d) 163 163 { 164 // FIXME 165 const unsigned char buf[9] = {0xd3, STORE_ 64(d)};164 // FIXME optimization 165 const unsigned char buf[9] = {0xd3, STORE_BE64(d)}; 166 166 msgpack_pack_append_buffer(x, buf, 9); 167 167 } … … 175 175 { 176 176 uint32_t n = *((uint32_t*)&d); // FIXME 177 const unsigned char buf[5] = {0xca, STORE_ 32(n)};177 const unsigned char buf[5] = {0xca, STORE_BE32(n)}; 178 178 msgpack_pack_append_buffer(x, buf, 5); 179 179 } … … 182 182 { 183 183 uint64_t n = *((uint64_t*)&d); // FIXME 184 const unsigned char buf[9] = {0xcb, STORE_ 64(n)};184 const unsigned char buf[9] = {0xcb, STORE_BE64(n)}; 185 185 msgpack_pack_append_buffer(x, buf, 9); 186 186 } … … 201 201 * Boolean 202 202 */ 203 203 204 inline void msgpack_pack_true(msgpack_pack_context x) 204 205 { … … 225 226 } else if(n < 65536) { 226 227 uint16_t d = (uint16_t)n; 227 unsigned char buf[3] = {0xdc, STORE_ 16(d)};228 unsigned char buf[3] = {0xdc, STORE_BE16(d)}; 228 229 msgpack_pack_append_buffer(x, buf, 3); 229 230 } else { 230 231 uint32_t d = (uint32_t)n; 231 unsigned char buf[5] = {0xdd, STORE_ 32(d)};232 unsigned char buf[5] = {0xdd, STORE_BE32(d)}; 232 233 msgpack_pack_append_buffer(x, buf, 5); 233 234 } … … 246 247 } else if(n < 65536) { 247 248 uint16_t d = (uint16_t)n; 248 unsigned char buf[3] = {0xde, STORE_ 16(d)};249 unsigned char buf[3] = {0xde, STORE_BE16(d)}; 249 250 msgpack_pack_append_buffer(x, buf, 3); 250 251 } else { 251 252 uint32_t d = (uint32_t)n; 252 unsigned char buf[5] = {0xdf, STORE_ 32(d)};253 msgpack_pack_append_buffer(x, buf, 5); 254 } 255 } 256 257 258 /* 259 * String253 unsigned char buf[5] = {0xdf, STORE_BE32(d)}; 254 msgpack_pack_append_buffer(x, buf, 5); 255 } 256 } 257 258 259 /* 260 * Raw 260 261 */ 261 262 … … 273 274 } else if(l < 65536) { 274 275 uint16_t d = (uint16_t)l; 275 unsigned char buf[3] = {0xda, STORE_ 16(d)};276 unsigned char buf[3] = {0xda, STORE_BE16(d)}; 276 277 msgpack_pack_append_buffer(x, buf, 3); 277 278 } else { 278 279 uint32_t d = (uint32_t)l; 279 unsigned char buf[5] = {0xdb, STORE_ 32(d)};280 unsigned char buf[5] = {0xdb, STORE_BE32(d)}; 280 281 msgpack_pack_append_buffer(x, buf, 5); 281 282 } … … 284 285 285 286 287 #undef STORE_BE16(d) 288 #undef STORE_BE32(d) 289 #undef STORE_BE64(d) 290 291 286 292 #endif /* msgpack/pack/inline_impl.h */ 287 293 -
lang/c/msgpack/trunk/msgpack/unpack/inline_context.h
r17708 r18599 26 26 #endif 27 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 28 32 typedef struct { 29 33 msgpack_object obj; … … 48 52 #define msgpack_unpacker_data(unpacker) (unpacker)->stack[0].obj 49 53 54 #ifdef __cplusplus 55 } 56 #endif 50 57 51 58 #endif /* msgpack/unpack/inline_context.h */ -
lang/c/msgpack/trunk/msgpack/unpack/inline_impl.h
r17708 r18599 23 23 #include <arpa/inet.h> 24 24 /*#include <stdio.h>*/ 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 25 29 26 30 // Positive FixNum 0xxxxxxx 0x00 - 0x7f … … 72 76 #endif 73 77 74 static inline uint64_t ntohll(uint64_t x) { 75 #ifdef __LITTLE_ENDIAN__ // FIXME 78 #define betoh16(x) ntohs(x) 79 #define betoh32(x) ntohl(x) 80 81 #ifdef __LITTLE_ENDIAN__ 76 82 #if defined(__bswap_64) 77 return __bswap_64(x); 83 # define betoh64(x) __bswap_64(x) 78 84 #elif defined(__DARWIN_OSSwapInt64) 79 return __DARWIN_OSSwapInt64(x); 85 # define betoh64(x) __DARWIN_OSSwapInt64(x) 80 86 #else 87 static inline uint64_t betoh64(uint64_t x) { 81 88 return ((x << 56) & 0xff00000000000000ULL ) | 82 89 ((x << 40) & 0x00ff000000000000ULL ) | … … 87 94 ((x >> 40) & 0x000000000000ff00ULL ) | 88 95 ((x >> 56) & 0x00000000000000ffULL ) ; 96 } 89 97 #endif 90 98 #else 91 return x; 92 #endif 93 } 99 #define betoh64(x) (x) 100 #endif 101 94 102 95 103 typedef enum { … … 213 221 214 222 #define PTR_CAST_8(ptr) (*(uint8_t*)ptr) 215 #define PTR_CAST_16(ptr) ntohs(*(uint16_t*)ptr)216 #define PTR_CAST_32(ptr) ntohl(*(uint32_t*)ptr)217 #define PTR_CAST_64(ptr) ntohll(*(uint64_t*)ptr)223 #define PTR_CAST_16(ptr) betoh16(*(uint16_t*)ptr) 224 #define PTR_CAST_32(ptr) betoh32(*(uint32_t*)ptr) 225 #define PTR_CAST_64(ptr) betoh64(*(uint64_t*)ptr) 218 226 219 227 if(p == pe) { goto _out; } … … 435 443 436 444 445 #ifdef betoh16(x) 446 #undef betoh16(x) 447 #endif 448 449 #ifdef betoh32(x) 450 #undef betoh32(x) 451 #endif 452 453 #ifdef betoh64(x) 454 #undef betoh64(x) 455 #endif 456 457 #ifdef __cplusplus 458 } 459 #endif 460 437 461 #endif /* msgpack/unpack/inline_impl.h */ 438 462
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)