msgpack-c-6.0.1/example/0000755000175000017460000000000014602664033014027 5ustar kondowheelmsgpack-c-6.0.1/example/lib_buffer_unpack.c0000644000175000017460000000704114602664033017635 0ustar kondowheel#include #include #include typedef struct receiver { msgpack_sbuffer sbuf; size_t rest; } receiver; void receiver_init(receiver *r) { msgpack_packer pk; msgpack_sbuffer_init(&r->sbuf); msgpack_packer_init(&pk, &r->sbuf, msgpack_sbuffer_write); /* 1st object */ msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* 2nd object */ msgpack_pack_str(&pk, 6); msgpack_pack_str_body(&pk, "second", 6); /* 3rd object */ msgpack_pack_array(&pk, 2); msgpack_pack_int(&pk, 42); msgpack_pack_false(&pk); r->rest = r->sbuf.size; } size_t receiver_recv(receiver *r, char* buf, size_t try_size) { size_t off = r->sbuf.size - r->rest; size_t actual_size = try_size; if (actual_size > r->rest) actual_size = r->rest; memcpy(buf, r->sbuf.data + off, actual_size); r->rest -= actual_size; return actual_size; } size_t receiver_to_unpacker(receiver* r, size_t request_size, msgpack_unpacker *unpacker) { size_t recv_len; // make sure there's enough room, or expand the unpacker accordingly if (msgpack_unpacker_buffer_capacity(unpacker) < request_size) { msgpack_unpacker_reserve_buffer(unpacker, request_size); assert(msgpack_unpacker_buffer_capacity(unpacker) >= request_size); } recv_len = receiver_recv(r, msgpack_unpacker_buffer(unpacker), request_size); msgpack_unpacker_buffer_consumed(unpacker, recv_len); return recv_len; } #define EACH_RECV_SIZE 4 void unpack(receiver* r) { /* buf is allocated by unpacker. */ msgpack_unpacker* unp = msgpack_unpacker_new(100); msgpack_unpacked result; msgpack_unpack_return ret; size_t recv_len; int recv_count = 0; int i = 0; msgpack_unpacked_init(&result); while (true) { recv_len = receiver_to_unpacker(r, EACH_RECV_SIZE, unp); if (recv_len == 0) break; // (reached end of input) #if defined(_MSC_VER) || defined(__MINGW32__) printf("receive count: %d %Id bytes received.\n", recv_count++, recv_len); #else // defined(_MSC_VER) || defined(__MINGW32__) printf("receive count: %d %zd bytes received.\n", recv_count++, recv_len); #endif // defined(_MSC_VER) || defined(__MINGW32__) ret = msgpack_unpacker_next(unp, &result); while (ret == MSGPACK_UNPACK_SUCCESS) { msgpack_object obj = result.data; /* Use obj. */ printf("Object no %d:\n", ++i); msgpack_object_print(stdout, obj); printf("\n"); /* If you want to allocate something on the zone, you can use zone. */ /* msgpack_zone* zone = result.zone; */ /* The lifetime of the obj and the zone, */ ret = msgpack_unpacker_next(unp, &result); } if (ret == MSGPACK_UNPACK_PARSE_ERROR) { printf("The data in the buf is invalid format.\n"); msgpack_unpacked_destroy(&result); return; } } msgpack_unpacked_destroy(&result); msgpack_unpacker_free(unp); } int main(void) { receiver r; receiver_init(&r); unpack(&r); return 0; } /* Output */ /* receive count: 0 4 bytes received. receive count: 1 4 bytes received. receive count: 2 4 bytes received. Object no 1: [1, true, "example"] receive count: 3 4 bytes received. receive count: 4 4 bytes received. Object no 2: "second" receive count: 5 1 bytes received. Object no 3: [42, false] */ msgpack-c-6.0.1/example/cmake/0000755000175000017460000000000014602712217015105 5ustar kondowheelmsgpack-c-6.0.1/example/cmake/CMakeLists.txt0000644000175000017460000000102314602712217017641 0ustar kondowheelcmake_minimum_required (VERSION 3.5) project (example) if(EXAMPLE_MSGPACK_EMBEDDED) add_subdirectory(msgpack-c) set(msgpack-c_DIR ${CMAKE_CURRENT_BINARY_DIR}/msgpack-c) endif() find_package(msgpack-c REQUIRED) add_executable (${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/../simple_c.c) target_link_libraries(${PROJECT_NAME} msgpack-c) if(TARGET msgpack-c-static) add_executable (${PROJECT_NAME}-static ${CMAKE_CURRENT_LIST_DIR}/../simple_c.c) target_link_libraries(${PROJECT_NAME}-static msgpack-c-static) endif() msgpack-c-6.0.1/example/simple_c.c0000644000175000017460000000227114602664033015770 0ustar kondowheel#include #include void print(char const* buf,size_t len) { size_t i = 0; for(; i < len ; ++i) printf("%02x ", 0xff & buf[i]); printf("\n"); } int main(void) { msgpack_sbuffer sbuf; msgpack_packer pk; msgpack_zone mempool; msgpack_object deserialized; /* msgpack::sbuffer is a simple buffer implementation. */ msgpack_sbuffer_init(&sbuf); /* serialize values into the buffer using msgpack_sbuffer_write callback function. */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); print(sbuf.data, sbuf.size); /* deserialize the buffer into msgpack_object instance. */ /* deserialized object is valid during the msgpack_zone instance alive. */ msgpack_zone_init(&mempool, 2048); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); /* print the deserialized object. */ msgpack_object_print(stdout, deserialized); puts(""); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); return 0; } msgpack-c-6.0.1/example/speed_test_uint64_array.c0000644000175000017460000000140614602664033020742 0ustar kondowheel#include void test() { uint64_t test_u64 = 0xFFF0000000000001LL; size_t size = 10000000; msgpack_sbuffer buf; msgpack_packer * pk; size_t upk_pos = 0; msgpack_unpacked msg; msgpack_sbuffer_init(&buf); pk = msgpack_packer_new(&buf, msgpack_sbuffer_write); msgpack_pack_array(pk, size); { size_t idx = 0; for (; idx < size; ++idx) msgpack_pack_uint64(pk, test_u64); } msgpack_packer_free(pk); msgpack_unpacked_init(&msg); while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos) == MSGPACK_UNPACK_SUCCESS) { } msgpack_unpacked_destroy(&msg); msgpack_sbuffer_destroy(&buf); } int main(void) { int i = 0; for (; i < 10; ++i) test(); return 0; } msgpack-c-6.0.1/example/CMakeLists.txt0000644000175000017460000000250514602664033016571 0ustar kondowheelFIND_PACKAGE (cJSON) LIST (APPEND exec_PROGRAMS boundary.c lib_buffer_unpack.c simple_c.c speed_test_uint32_array.c speed_test_uint64_array.c user_buffer_unpack.c ) IF (cJSON_FOUND) LIST (APPEND exec_PROGRAMS jsonconv.c) ENDIF () FOREACH (source_file ${exec_PROGRAMS}) GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) ADD_EXECUTABLE ( ${source_file_we} ${source_file} ) TARGET_LINK_LIBRARIES (${source_file_we} msgpack-c ) IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra") ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags") ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_C_FLAGS MATCHES "/W[0-4]") STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") ELSE () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") ENDIF () ENDIF () ENDFOREACH () IF (cJSON_FOUND) TARGET_LINK_LIBRARIES (jsonconv ${CJSON_LIBRARIES}) TARGET_INCLUDE_DIRECTORIES(jsonconv PRIVATE ${CJSON_INCLUDE_DIRS}) ENDIF () msgpack-c-6.0.1/example/boundary.c0000644000175000017460000003765314602664033016034 0ustar kondowheel/* gcc boundary.c -o boundary -Wconversion -Wpointer-sign */ #include #include #include static inline unsigned char atohex(char a) { int x; if (a >= 'a') { x = a - 'a' + 10; } else if (a >= 'A') { x = a - 'A' + 10; } else { x = a - '0'; } assert(x >= 0 && x < 16); return (unsigned char)x; } // Return 0 if equal static inline int bytesncmp(char *data, const char *bytes, size_t len) { size_t n = len >> 1; size_t i = 0; int diff; for (; i < n; i++) { diff = (unsigned char)data[i] - (atohex(bytes[2 * i]) << 4) - atohex(bytes[2 * i + 1]); if (diff != 0) { return diff; } } return 0; } int main() { msgpack_sbuffer sbuf; msgpack_packer *x; size_t offset = 0; char data[65536]; msgpack_timestamp ts[] = { { 0xFFFFFFFF, 0 }, { 0x100000000, 0 }, { 0x3FFFFFFFF, 0 }, { 0x400000000, 0 }, { INT64_MAX, UINT32_MAX } }; #define check_sbuffer(b) \ do { \ size_t len = strlen(#b); \ assert((sbuf.size - offset) * 2 == len); \ assert(bytesncmp(sbuf.data + offset, #b, len) == 0); \ offset = sbuf.size; \ } while (0) msgpack_sbuffer_init(&sbuf); x = msgpack_packer_new(&sbuf, msgpack_sbuffer_write); msgpack_pack_fix_uint8(x, 0); check_sbuffer(cc00); /* cc 00 */ msgpack_pack_fix_uint8(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_fix_uint16(x, 0); check_sbuffer(cd0000); /* cd 00 00 */ msgpack_pack_fix_uint16(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_fix_uint32(x, 0); check_sbuffer(ce00000000); /* ce 00 00 00 00 */ msgpack_pack_fix_uint32(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */ msgpack_pack_fix_uint64(x, 0); check_sbuffer(cf0000000000000000); /* cf 00 00 00 00 00 00 00 00 */ msgpack_pack_fix_uint64(x, 0xFFFFFFFFFFFFFFFF); check_sbuffer(cfffffffffffffffff); /* cf ff ff ff ff ff ff ff ff */ msgpack_pack_uint8(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_uint8(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_uint8(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_uint8(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_uint16(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_uint16(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_uint16(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_uint16(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_uint16(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_uint16(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_uint32(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_uint32(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_uint32(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_uint32(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_uint32(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_uint32(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_uint32(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */ msgpack_pack_uint32(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */ msgpack_pack_uint64(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_uint64(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_uint64(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_uint64(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_uint64(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_uint64(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_uint64(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */ msgpack_pack_uint64(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */ msgpack_pack_uint64(x, 0x100000000); check_sbuffer(cf0000000100000000); /* cf 00 00 00 01 00 00 00 00 */ msgpack_pack_uint64(x, 0xFFFFFFFFFFFFFFFF); check_sbuffer(cfffffffffffffffff); /* cf ff ff ff ff ff ff ff ff */ msgpack_pack_fix_int8(x, 0x7F); check_sbuffer(d07f); /* d0 7f */ msgpack_pack_fix_int8(x, -0x7F-1); check_sbuffer(d080); /* d0 80 */ msgpack_pack_fix_int16(x, 0x7FFF); check_sbuffer(d17fff); /* d1 7f ff */ msgpack_pack_fix_int16(x, -0x7FFF-1); check_sbuffer(d18000); /* d1 80 00 */ msgpack_pack_fix_int32(x, 0x7FFFFFFF); check_sbuffer(d27fffffff); /* d2 7f ff ff ff */ msgpack_pack_fix_int32(x, -0x7FFFFFFF-1); check_sbuffer(d280000000); /* d2 80 00 00 00 */ msgpack_pack_fix_int64(x, 0x7FFFFFFFFFFFFFFF); check_sbuffer(d37fffffffffffffff); /* d3 7f ff ff ff ff ff ff ff */ msgpack_pack_fix_int64(x, -0x7FFFFFFFFFFFFFFF-1); check_sbuffer(d38000000000000000); /* d3 80 00 00 00 00 00 00 00 */ msgpack_pack_int8(x, -0x7F-1); check_sbuffer(d080); /* d0 80 */ msgpack_pack_int8(x, -0x21); check_sbuffer(d0df); /* d0 df */ msgpack_pack_int8(x, -0x20); check_sbuffer(e0); /* e0 */ msgpack_pack_int8(x, -1); check_sbuffer(ff); /* ff */ msgpack_pack_int8(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_int8(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_int16(x, -0x7FFF-1); check_sbuffer(d18000); /* d1 80 00 */ msgpack_pack_int16(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */ msgpack_pack_int16(x, -0x80); check_sbuffer(d080); /* d0 80 */ msgpack_pack_int16(x, -0x21); check_sbuffer(d0df); /* d0 df */ msgpack_pack_int16(x, -0x20); check_sbuffer(e0); /* e0 */ msgpack_pack_int16(x, -0x1); check_sbuffer(ff); /* ff */ msgpack_pack_int16(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_int16(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_int16(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_int16(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_int16(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_int16(x, 0x7FFF); check_sbuffer(cd7fff); /* cd 7f ff */ msgpack_pack_int32(x, -0x7FFFFFFF-1); check_sbuffer(d280000000); /* d2 80 00 00 00 */ msgpack_pack_int32(x, -0x8001); check_sbuffer(d2ffff7fff); /* d2 ff ff 7f ff */ msgpack_pack_int32(x, -0x8000); check_sbuffer(d18000); /* d1 80 00 */ msgpack_pack_int32(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */ msgpack_pack_int32(x, -0x80); check_sbuffer(d080); /* d0 80 */ msgpack_pack_int32(x, -0x21); check_sbuffer(d0df); /* d0 df */ msgpack_pack_int32(x, -0x20); check_sbuffer(e0); /* e0 */ msgpack_pack_int32(x, -0x1); check_sbuffer(ff); /* ff */ msgpack_pack_int32(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_int32(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_int32(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_int32(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_int32(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_int32(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_int32(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */ msgpack_pack_int32(x, 0x7FFFFFFF); check_sbuffer(ce7fffffff); /* ce 7f ff ff ff */ msgpack_pack_int64(x, -0x7FFFFFFFFFFFFFFF-1); check_sbuffer(d38000000000000000); /* d3 80 00 00 00 00 00 00 00 */ msgpack_pack_int64(x, -((1LL<<31)+1)); check_sbuffer(d3ffffffff7fffffff); /* d3 ff ff ff ff 7f ff ff ff */ msgpack_pack_int64(x, -(1LL<<31)); check_sbuffer(d280000000); /* d2 80 00 00 00 */ msgpack_pack_int64(x, -0x8001); check_sbuffer(d2ffff7fff); /* d2 ff ff 7f ff */ msgpack_pack_int64(x, -0x8000); check_sbuffer(d18000); /* d1 80 00 */ msgpack_pack_int64(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */ msgpack_pack_int64(x, -0x80); check_sbuffer(d080); /* d0 80 */ msgpack_pack_int64(x, -0x21); check_sbuffer(d0df); /* d0 df */ msgpack_pack_int64(x, -0x20); check_sbuffer(e0); /* e0 */ msgpack_pack_int64(x, -0x1); check_sbuffer(ff); /* ff */ msgpack_pack_int64(x, 0); check_sbuffer(00); /* 00 */ msgpack_pack_int64(x, 0x7F); check_sbuffer(7f); /* 7f */ msgpack_pack_int64(x, 0x80); check_sbuffer(cc80); /* cc 80 */ msgpack_pack_int64(x, 0xFF); check_sbuffer(ccff); /* cc ff */ msgpack_pack_int64(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */ msgpack_pack_int64(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */ msgpack_pack_int64(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */ msgpack_pack_int64(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */ msgpack_pack_int64(x, 0x100000000); check_sbuffer(cf0000000100000000); /* cf 00 00 00 01 00 00 00 00 */ msgpack_pack_int64(x, 0x7FFFFFFFFFFFFFFF); check_sbuffer(cf7fffffffffffffff); /* cf 7f ff ff ff ff ff ff ff */ msgpack_pack_nil(x); check_sbuffer(c0); /* c0 */ msgpack_pack_false(x); check_sbuffer(c2); /* c2 */ msgpack_pack_true(x); check_sbuffer(c3); /* c3 */ msgpack_pack_float(x, 1.0); check_sbuffer(ca3f800000); /* ca 3f 80 00 00 */ msgpack_pack_double(x, 1.0); check_sbuffer(cb3ff0000000000000); /* cb 3f f0 00 00 00 00 00 00 */ msgpack_pack_unsigned_char(x, UINT8_MAX); /* same as msgpack_pack_uint8() */ msgpack_pack_unsigned_short(x, (unsigned short)UINT64_MAX); msgpack_pack_unsigned_int(x, (unsigned int)UINT64_MAX); msgpack_pack_unsigned_long(x, (unsigned long)UINT64_MAX); msgpack_pack_unsigned_long_long(x, (unsigned long long)UINT64_MAX); msgpack_pack_signed_char(x, INT8_MAX); /* same as msgpack_pack_int8() */ #define check_sbuffer_n(b) \ do { \ size_t len = strlen(#b); \ assert(bytesncmp(sbuf.data + offset, #b, len) == 0); \ offset = sbuf.size; \ } while (0) #define fill_str(n) msgpack_pack_str_body(x, data, n) offset = sbuf.size; msgpack_pack_str(x, 0); /* "" */ check_sbuffer(a0); /* a0 */ msgpack_pack_str(x, 31); fill_str(31); check_sbuffer_n(bf); /* bf ... */ msgpack_pack_str(x, 32); fill_str(32); check_sbuffer_n(d920); /* d9 20 ... */ msgpack_pack_str(x, 255); fill_str(255); check_sbuffer_n(d9ff); /* d9 ff ... */ msgpack_pack_str(x, 256); fill_str(256); check_sbuffer_n(da0100); /* da 01 00 ... */ msgpack_pack_str(x, 65535); fill_str(65535); check_sbuffer_n(daffff); /* da ff ff ... */ msgpack_pack_str(x, 65536); fill_str(65536); check_sbuffer_n(db00010000); /* db 00 01 00 00 ... */ #define fill_map(n) \ do { \ size_t i = 0; \ for (; i < n * 2; i++) { msgpack_pack_int8(x, 0x1); } \ } while (0); msgpack_pack_map(x, 0); /* {} */ check_sbuffer(80); /* 80 */ msgpack_pack_map(x, 1); fill_map(1); check_sbuffer_n(81); /* 81 ... */ msgpack_pack_map(x, 15); fill_map(15); check_sbuffer_n(8f); /* 8f ... */ msgpack_pack_map(x, 16); fill_map(16); check_sbuffer_n(de0010); /* de 00 10 ... */ msgpack_pack_map(x, 65535); fill_map(65535); check_sbuffer_n(deffff); /* de ff ff ... */ msgpack_pack_map(x, 65536); fill_map(65536); check_sbuffer_n(df00010000); /* df 00 01 00 00 ... */ #define fill_array(n) \ do { \ size_t i = 0; \ for (; i < n; i++) { msgpack_pack_int8(x, 0x1); } \ } while (0); msgpack_pack_array(x, 0); /* [] */ check_sbuffer(90); /* 90 */ msgpack_pack_array(x, 1); fill_array(1); check_sbuffer_n(91); /* 91 ... */ msgpack_pack_array(x, 15); fill_array(15); check_sbuffer_n(9f); /* 9f ... */ msgpack_pack_array(x, 16); fill_array(16); check_sbuffer_n(dc0010); /* dc 00 10 ... */ msgpack_pack_array(x, 65535); fill_array(65535); check_sbuffer_n(dcffff); /* dc ff ff ... */ msgpack_pack_array(x, 65536); fill_array(65536); check_sbuffer_n(dd00010000); /* dd 00 01 00 00 ... */ #define fill_bin(n) msgpack_pack_bin_body(x, data, n) msgpack_pack_bin(x, 0); check_sbuffer(c400); /* c4 00 */ msgpack_pack_bin(x, 1); fill_bin(1); check_sbuffer_n(c401); /* c4 01 ... */ msgpack_pack_bin(x, 255); fill_bin(255); check_sbuffer_n(c4ff); /* c4 ff ... */ msgpack_pack_bin(x, 256); fill_bin(256); check_sbuffer_n(c50100); /* c5 01 00 ... */ msgpack_pack_bin(x, 65535); fill_bin(65535); check_sbuffer_n(c5ffff); /* c5 ff ff ... */ msgpack_pack_bin(x, 65536); fill_bin(65536); check_sbuffer_n(c600010000); /* c6 00 01 00 00 ... */ #define fill_ext(n) msgpack_pack_ext_body(x, data, n) msgpack_pack_ext(x, 1, 0x7F); fill_ext(1); check_sbuffer_n(d47f); /* d4 7f ... */ msgpack_pack_ext(x, 2, 0x7F); fill_ext(2); check_sbuffer_n(d57f); /* d5 7f ... */ msgpack_pack_ext(x, 4, 0x7F); fill_ext(4); check_sbuffer_n(d67f); /* d6 7f ... */ msgpack_pack_ext(x, 8, 0x7F); fill_ext(8); check_sbuffer_n(d77f); /* d7 7f ... */ msgpack_pack_ext(x, 16, 0x7F); fill_ext(16); check_sbuffer_n(d87f); /* d8 7f ... */ msgpack_pack_ext(x, 0, 0x7F); check_sbuffer(c7007f); /* c7 00 7f */ msgpack_pack_ext(x, 3, 0x7F); fill_ext(3); check_sbuffer_n(c7037f); /* c7 03 7f */ msgpack_pack_ext(x, 5, 0x7F); fill_ext(5); check_sbuffer_n(c7057f); /* c7 05 7f */ msgpack_pack_ext(x, 17, 0x7F); fill_ext(17); check_sbuffer_n(c7117f); /* c7 11 7f */ msgpack_pack_ext(x, 255, 0x7F); fill_ext(255); check_sbuffer_n(c7ff7f); /* c7 ff 7f ... */ msgpack_pack_ext(x, 256, 0x7F); fill_ext(256); check_sbuffer_n(c801007f); /* c8 01 00 7f ... */ msgpack_pack_ext(x, 65535, 0x7F); fill_ext(65535); check_sbuffer_n(c8ffff7f); /* c8 ff ff 7f ... */ msgpack_pack_ext(x, 65536, 0x7F); fill_ext(65536); check_sbuffer_n(c9000100007f); /* c9 00 01 00 00 7f ... */ msgpack_pack_timestamp(x, ts); check_sbuffer(d6ffffffffff); /* d6 ff ff ff ff ff */ msgpack_pack_timestamp(x, ts + 1); check_sbuffer(d7ff0000000100000000); /* d7 ff 00 00 00 01 00 00 00 00 */ msgpack_pack_timestamp(x, ts + 2); check_sbuffer(d7ff00000003ffffffff); /* d7 ff 00 00 00 03 ff ff ff ff */ msgpack_pack_timestamp(x, ts + 3); check_sbuffer(c70cff000000000000000400000000); /* c7 0c ff 00 00 00 00 00 00 00 04 00 00 00 00 */ msgpack_pack_timestamp(x, ts + 4); check_sbuffer(c70cffffffffff7fffffffffffffff); /* c7 0c ff ff ff ff ff 7f ff ff ff ff ff ff ff */ msgpack_sbuffer_destroy(&sbuf); msgpack_packer_free(x); return 0; } msgpack-c-6.0.1/example/speed_test_uint32_array.c0000644000175000017460000000132214602664033020732 0ustar kondowheel#include void test() { size_t size = 10000000; msgpack_sbuffer buf; msgpack_packer * pk; size_t upk_pos = 0; msgpack_unpacked msg; msgpack_sbuffer_init(&buf); pk = msgpack_packer_new(&buf, msgpack_sbuffer_write); msgpack_pack_array(pk, size); { size_t idx = 0; for (; idx < size; ++idx) msgpack_pack_uint32(pk, 1); } msgpack_packer_free(pk); msgpack_unpacked_init(&msg); while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos) == MSGPACK_UNPACK_SUCCESS) { } msgpack_unpacked_destroy(&msg); msgpack_sbuffer_destroy(&buf); } int main(void) { int i = 0; for (; i < 10; ++i) test(); return 0; } msgpack-c-6.0.1/example/jsonconv.c0000644000175000017460000003054314602664033016037 0ustar kondowheel#include #include #include #include #include #include #if defined(_MSC_VER) #if _MSC_VER >= 1800 #include #else #define PRIu64 "I64u" #define PRIi64 "I64i" #define PRIi8 "i" #endif #else #include #endif #if defined(_KERNEL_MODE) # undef snprintf # define snprintf _snprintf #endif #define DEBUG(...) printf(__VA_ARGS__) static char *format_string(const char *input) { const char *inptr; char *output; char *outptr; size_t output_length = 0; /* numbers of additional characters*/ size_t escape_characters = 0; if (input == NULL) { return NULL; } for (inptr = input; *inptr; inptr++) { switch (*inptr) { case '\"': case '\\': case '\b': case '\f': case '\n': case '\r': case '\t': /* one character escape sequence */ escape_characters++; break; default: break; } } output_length = (size_t)(inptr - input) + escape_characters; output = (char *)malloc(output_length + 1); if (output == NULL) { return NULL; } /* no add characters*/ if (escape_characters == 0) { memcpy(output, input, output_length); output[output_length] = '\0'; return output; } outptr = output; /* copy string */ for (inptr = input; *inptr != '\0'; (void)inptr++, outptr++) { if ((*inptr > 31) && (*inptr != '\"') && (*inptr != '\\')) { /* normal character, copy */ *outptr = *inptr; } else { /* character needs to be escaped */ *outptr++ = '\\'; switch (*inptr) { case '\\': *outptr = '\\'; break; case '\"': *outptr = '\"'; break; case '\b': *outptr = 'b'; break; case '\f': *outptr = 'f'; break; case '\n': *outptr = 'n'; break; case '\r': *outptr = 'r'; break; case '\t': *outptr = 't'; break; default: break; } } } output[output_length] = '\0'; return output; } /* * Pack cJSON object. * return 0 success, others failed */ static int parse_cjson_object(msgpack_packer *pk, cJSON *node) { int ret, sz, i; cJSON *child; char *strvalue; if (node == NULL) { return -1; } switch (node->type & 0xFF) { case cJSON_Invalid: return -1; case cJSON_False: return msgpack_pack_false(pk); case cJSON_True: return msgpack_pack_true(pk); case cJSON_NULL: return msgpack_pack_nil(pk); case cJSON_String: strvalue = format_string(node->valuestring); if (strvalue != NULL) { ret = msgpack_pack_str_with_body(pk, strvalue, strlen(strvalue)); free(strvalue); return ret; } else { return -1; } case cJSON_Number: if (isnan(node->valuedouble) || isinf(node->valuedouble)) { ret = msgpack_pack_nil(pk); } else if (node->valuedouble == node->valueint) { ret = msgpack_pack_int(pk, node->valueint); } else { ret = msgpack_pack_double(pk, node->valuedouble); } return ret; case cJSON_Array: sz = cJSON_GetArraySize(node); if (msgpack_pack_array(pk, sz) != 0) { return -1; } for (i = 0; i < sz; i++) { if (parse_cjson_object(pk, cJSON_GetArrayItem(node, i)) != 0) { return -1; } } return 0; case cJSON_Object: sz = cJSON_GetArraySize(node); if (msgpack_pack_map(pk, sz) != 0) { return -1; } for (i = 0; i < sz; i++) { child = cJSON_GetArrayItem(node, i); strvalue = format_string(child->string); if (strvalue == NULL) { return -1; } if (msgpack_pack_str_with_body(pk, strvalue, strlen(strvalue)) != 0) { free(strvalue); return -1; } free(strvalue); if (parse_cjson_object(pk, child) != 0) { return -1; } } return 0; default: DEBUG("unknown type.\n"); return -1; } return 0; } /* * Pack json string to msgpack format data. * return 0 success, -1 failed */ int msgpack_pack_jsonstr(msgpack_packer *pk, const char *jsonstr) { int status; cJSON *node; const char *end = NULL; if (pk == NULL || jsonstr == NULL) { return -1; } node = cJSON_ParseWithOpts(jsonstr, &end, 1); if (node == NULL) { DEBUG("parse error: unexpected string `%s`\n", end); return -1; } status = parse_cjson_object(pk, node); cJSON_Delete(node); return status; } static int bytes_contain_zero(const msgpack_object_bin *bin) { size_t i; for (i = 0; i < bin->size; i++) { if (bin->ptr[i] == 0) { return 1; } } return 0; } #define PRINT_JSONSTR_CALL(ret, func, aux_buffer, aux_buffer_size, ...) \ ret = func(aux_buffer, aux_buffer_size, __VA_ARGS__); \ if (ret <= 0) \ return ret; \ if (ret > aux_buffer_size) \ return 0; \ aux_buffer = aux_buffer + ret; \ aux_buffer_size = aux_buffer_size - ret /* * Convert msgpack format data to json string. * return >0: success, 0: length of buffer not enough, -1: failed */ size_t msgpack_object_print_jsonstr(char *buffer, size_t length, const msgpack_object o) { char *aux_buffer = buffer; size_t aux_buffer_size = length; size_t ret; switch (o.type) { case MSGPACK_OBJECT_NIL: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "null"); break; case MSGPACK_OBJECT_BOOLEAN: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, (o.via.boolean ? "true" : "false")); break; case MSGPACK_OBJECT_POSITIVE_INTEGER: #if defined(PRIu64) PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIu64, o.via.u64); #else if (o.via.u64 > ULONG_MAX) { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%lu", ULONG_MAX); } else { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%lu", (unsigned long)o.via.u64); } #endif break; case MSGPACK_OBJECT_NEGATIVE_INTEGER: #if defined(PRIi64) PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIi64, o.via.i64); #else if (o.via.i64 > LONG_MAX) { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", LONG_MAX); } else if (o.via.i64 < LONG_MIN) { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", LONG_MIN); } else { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", (signed long)o.via.i64); } #endif break; case MSGPACK_OBJECT_FLOAT32: case MSGPACK_OBJECT_FLOAT64: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%f", o.via.f64); break; case MSGPACK_OBJECT_STR: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"%.*s\"", (int)o.via.str.size, o.via.str.ptr); break; case MSGPACK_OBJECT_BIN: if (bytes_contain_zero(&o.via.bin)) { DEBUG("the value contains zero\n"); return -1; } PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"%.*s\"", (int)o.via.bin.size, o.via.bin.ptr); break; case MSGPACK_OBJECT_EXT: DEBUG("not support type: MSGPACK_OBJECT_EXT.\n"); return -1; case MSGPACK_OBJECT_ARRAY: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "["); if (o.via.array.size != 0) { msgpack_object *p = o.via.array.ptr; msgpack_object *const pend = o.via.array.ptr + o.via.array.size; PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, *p); ++p; for (; p < pend; ++p) { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ","); PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, *p); } } PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "]"); break; case MSGPACK_OBJECT_MAP: PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "{"); if (o.via.map.size != 0) { msgpack_object_kv *p = o.via.map.ptr; msgpack_object_kv *const pend = o.via.map.ptr + o.via.map.size; for (; p < pend; ++p) { if (p->key.type != MSGPACK_OBJECT_STR) { DEBUG("the key of in a map must be string.\n"); return -1; } if (p != o.via.map.ptr) { PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ","); } PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, p->key); PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ":"); PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, p->val); } } PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "}"); break; default: DEBUG("unknown type.\n"); return -1; } return length - aux_buffer_size; } #undef PRINT_JSONSTR_CALL static void test(const char *name, const char *input, const char *expect) { msgpack_sbuffer sbuf; { // pack msgpack_packer pk; msgpack_sbuffer_init(&sbuf); msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); if (msgpack_pack_jsonstr(&pk, input) < 0) { msgpack_sbuffer_destroy(&sbuf); printf("%s: invalid json string.\n", name); return; } } { // unpack #define MAX_JSONLEN 1024 msgpack_zone z; msgpack_object obj; size_t jsonstrlen = MAX_JSONLEN - 1; char jsonparsed[MAX_JSONLEN]; msgpack_zone_init(&z, jsonstrlen); msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); jsonstrlen = msgpack_object_print_jsonstr(jsonparsed, jsonstrlen, obj); jsonparsed[jsonstrlen] = '\0'; //compare input and output if (expect == NULL) { expect = input; } if (strcmp(expect, jsonparsed) == 0) { printf("%s: ok\n", name); } else { printf("%s: failed\n", name); } msgpack_zone_destroy(&z); } msgpack_sbuffer_destroy(&sbuf); } int main() { test("null", "null", NULL); test("boolean", "false", NULL); test("single string", "\"frsyuki\"", NULL); test("single number", "\"100\"", NULL); test("space", "[{\"valuespace\":\"\",\"\":\"keyspace\"},\"\",[\"\"]]", NULL); test("quote", "\"My name is Tom (\\\"Bee\\\") Kobe\"", NULL); test("escape", "\"\\\\b\\f\\n\\r\\t\"", NULL); test("escape2", "\"\b\f\n\r\t\"", "\"\\b\\f\\n\\r\\t\""); test("map", "{\"name\":\"Tom (\\\"Bee\\\") Kobe\",\"type\":\"image\",\"data\":{\"width\":360,\"height\":460,\"title\":\"View me\",\"ips\":[116,943,256,711]}}", NULL); test("array", "[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]", NULL); test("number array", "[[101,121,-33],[119,911,171],[0,2,-3]]", NULL); test("mix array", "[{\"name\":\"Tom\",\"city\":\"London\",\"country\":\"UK\",\"longitude\":23},{\"name\":\"Jack\",\"city\":\"Birmingham\",\"country\":\"UK\",\"longitude\":-22}]", NULL); test("unicode", "\"\\u5C71\\u5DDD\\u7570\\u57DF\\u98A8\\u6708\\u540C\\u5929\"", "\"山川異域風月同天\""); test("utf8", "\"山川異域風月同天\"", NULL); test("double", "12.34", "12.340000"); return 0; } msgpack-c-6.0.1/example/user_buffer_unpack.c0000644000175000017460000000411214602664033020041 0ustar kondowheel#include #include #include #define UNPACKED_BUFFER_SIZE 2048 void prepare(msgpack_sbuffer* sbuf) { msgpack_packer pk; msgpack_packer_init(&pk, sbuf, msgpack_sbuffer_write); /* 1st object */ msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* 2nd object */ msgpack_pack_str(&pk, 6); msgpack_pack_str_body(&pk, "second", 6); /* 3rd object */ msgpack_pack_array(&pk, 2); msgpack_pack_int(&pk, 42); msgpack_pack_false(&pk); } void unpack(char const* buf, size_t len) { /* buf is allocated by client. */ msgpack_unpacked result; size_t off = 0; msgpack_unpack_return ret; int i = 0; char unpacked_buffer[UNPACKED_BUFFER_SIZE]; msgpack_unpacked_init(&result); ret = msgpack_unpack_next(&result, buf, len, &off); while (ret == MSGPACK_UNPACK_SUCCESS) { msgpack_object obj = result.data; /* Use obj. */ printf("Object no %d:\n", ++i); msgpack_object_print(stdout, obj); printf("\n"); msgpack_object_print_buffer(unpacked_buffer, UNPACKED_BUFFER_SIZE, obj); printf("%s\n", unpacked_buffer); /* If you want to allocate something on the zone, you can use zone. */ /* msgpack_zone* zone = result.zone; */ /* The lifetime of the obj and the zone, */ ret = msgpack_unpack_next(&result, buf, len, &off); } msgpack_unpacked_destroy(&result); if (ret == MSGPACK_UNPACK_CONTINUE) { printf("All msgpack_object in the buffer is consumed.\n"); } else if (ret == MSGPACK_UNPACK_PARSE_ERROR) { printf("The data in the buf is invalid format.\n"); } } int main(void) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); prepare(&sbuf); unpack(sbuf.data, sbuf.size); msgpack_sbuffer_destroy(&sbuf); return 0; } /* Output */ /* Object no 1: [1, true, "example"] Object no 2: "second" Object no 3: [42, false] All msgpack_object in the buffer is consumed. */ msgpack-c-6.0.1/test/0000755000175000017460000000000014602664033013353 5ustar kondowheelmsgpack-c-6.0.1/test/fixint_c.cpp0000644000175000017460000000220414602664033015660 0ustar kondowheel#include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) TEST(fixint, size) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); size_t sum = 0; EXPECT_EQ(0, msgpack_pack_fix_int8(pk, 0)); EXPECT_EQ(sum+=2, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_int16(pk, 0)); EXPECT_EQ(sum+=3, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_int32(pk, 0)); EXPECT_EQ(sum+=5, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_int64(pk, 0)); EXPECT_EQ(sum+=9, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_uint8(pk, 0)); EXPECT_EQ(sum+=2, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_uint16(pk, 0)); EXPECT_EQ(sum+=3, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_uint32(pk, 0)); EXPECT_EQ(sum+=5, sbuf->size); EXPECT_EQ(0, msgpack_pack_fix_uint64(pk, 0)); EXPECT_EQ(sum+=9, sbuf->size); msgpack_sbuffer_free(sbuf); msgpack_packer_free(pk); } msgpack-c-6.0.1/test/buffer_c.cpp0000644000175000017460000001025614602664033015636 0ustar kondowheel#include #include #include #include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) #include #if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__) #define HAVE_SYS_UIO_H 1 #else #define HAVE_SYS_UIO_H 0 #endif TEST(buffer, zbuffer_c) { msgpack_zbuffer zbuf; EXPECT_TRUE(msgpack_zbuffer_init(&zbuf, 1, MSGPACK_ZBUFFER_INIT_SIZE)); EXPECT_EQ(0, msgpack_zbuffer_write(&zbuf, "a", 1)); EXPECT_EQ(0, msgpack_zbuffer_write(&zbuf, "a", 1)); EXPECT_EQ(0, msgpack_zbuffer_write(&zbuf, "a", 1)); EXPECT_EQ(0, msgpack_zbuffer_write(&zbuf, "", 0)); EXPECT_TRUE(msgpack_zbuffer_flush(&zbuf) != NULL); msgpack_zbuffer_destroy(&zbuf); } TEST(buffer, fbuffer_c) { #if defined(_MSC_VER) FILE* file; tmpfile_s(&file); #else // defined(_MSC_VER) FILE* file = tmpfile(); #endif // defined(_MSC_VER) void* fbuf = (void*)file; EXPECT_TRUE( file != NULL ); EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1)); EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1)); EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1)); fflush(file); rewind(file); for (size_t i=0; i < 3; ++i) { int ch = fgetc(file); EXPECT_TRUE(ch != EOF); EXPECT_EQ('a', (char) ch); } EXPECT_EQ(EOF, fgetc(file)); fclose(file); } TEST(buffer, sbuffer_c) { msgpack_sbuffer *sbuf; char *data; sbuf = msgpack_sbuffer_new(); EXPECT_TRUE(sbuf != NULL); EXPECT_EQ(0, msgpack_sbuffer_write(sbuf, "a", 1)); EXPECT_EQ(0, msgpack_sbuffer_write(sbuf, "b", 1)); EXPECT_EQ(0, msgpack_sbuffer_write(sbuf, "c", 1)); EXPECT_EQ(0, msgpack_sbuffer_write(sbuf, "", 0)); EXPECT_EQ(3U, sbuf->size); EXPECT_EQ(0, memcmp(sbuf->data, "abc", 3)); data = msgpack_sbuffer_release(sbuf); EXPECT_EQ(0, memcmp(data, "abc", 3)); EXPECT_EQ(0U, sbuf->size); EXPECT_TRUE(sbuf->data == NULL); free(data); msgpack_sbuffer_free(sbuf); } TEST(buffer, vrefbuffer_c) { const char *raw = "I was about to sail away in a junk," "When suddenly I heard" "The sound of stamping and singing on the bank--" "It was you and your friends come to bid me farewell." "The Peach Flower Lake is a thousand fathoms deep," "But it cannot compare, O Wang Lun," "With the depth of your love for me."; const size_t rawlen = strlen(raw); msgpack_vrefbuffer *vbuf; const int ref_size = 24, chunk_size = 128; size_t slices[] = {0, 9, 10, MSGPACK_VREFBUFFER_REF_SIZE, MSGPACK_VREFBUFFER_REF_SIZE + 1, ref_size, chunk_size + 1}; size_t iovcnt; const msgpack_iovec *iov; size_t len = 0, i; char *buf; vbuf = msgpack_vrefbuffer_new(ref_size, 0); for (i = 0; i < sizeof(slices) / sizeof(slices[0]); i++) { msgpack_vrefbuffer_write(vbuf, raw + len, slices[i]); len += slices[i]; } EXPECT_LT(len, rawlen); iov = msgpack_vrefbuffer_vec(vbuf); iovcnt = msgpack_vrefbuffer_veclen(vbuf); buf = (char *)malloc(rawlen); #if HAVE_SYS_UIO_H { int fd; char filename[] = "/tmp/mp.XXXXXX"; fd = mkstemp(filename); EXPECT_LT(0, fd); writev(fd, iov, (int)iovcnt); len = (size_t)lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); read(fd, buf, len); EXPECT_EQ(0, memcmp(buf, raw, len)); close(fd); unlink(filename); } #else { len = 0; for (i = 0; i < iovcnt; i++) { EXPECT_LT(len, rawlen); memcpy(buf + len, iov[i].iov_base, iov[i].iov_len); len += iov[i].iov_len; } EXPECT_EQ(0, memcmp(buf, raw, len)); } #endif free(buf); msgpack_vrefbuffer_free(vbuf); } msgpack-c-6.0.1/test/streaming_c.cpp0000644000175000017460000001530014602664033016351 0ustar kondowheel#include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) #include TEST(streaming, basic) { msgpack_sbuffer* buffer = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); // 1, 2, 3, "str", ["str_data"], "bin", ["bin_data"], {0.3: 0.4} EXPECT_EQ(0, msgpack_pack_int(pk, 1)); EXPECT_EQ(0, msgpack_pack_int(pk, 2)); EXPECT_EQ(0, msgpack_pack_int(pk, 3)); EXPECT_EQ(0, msgpack_pack_str(pk, 3)); EXPECT_EQ(0, msgpack_pack_str_body(pk, "str", 3)); EXPECT_EQ(0, msgpack_pack_array(pk, 1)); EXPECT_EQ(0, msgpack_pack_str(pk, 8)); EXPECT_EQ(0, msgpack_pack_str_body(pk, "str_data", 8)); EXPECT_EQ(0, msgpack_pack_bin(pk, 3)); EXPECT_EQ(0, msgpack_pack_bin_body(pk, "bin", 3)); EXPECT_EQ(0, msgpack_pack_array(pk, 1)); EXPECT_EQ(0, msgpack_pack_bin(pk, 8)); EXPECT_EQ(0, msgpack_pack_bin_body(pk, "bin_data", 8)); EXPECT_EQ(0, msgpack_pack_map(pk, 1)); EXPECT_EQ(0, msgpack_pack_float(pk, 0.4f)); EXPECT_EQ(0, msgpack_pack_double(pk, 0.8)); int max_count = 6; msgpack_packer_free(pk); const char* input = buffer->data; const char* const eof = input + buffer->size; msgpack_unpacker pac; msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE); msgpack_unpacked result; msgpack_unpacked_init(&result); int count = 0; while(count < max_count) { bool unpacked = false; msgpack_unpacker_reserve_buffer(&pac, 32*1024); while(!unpacked) { /* read buffer into msgpack_unapcker_buffer(&pac) upto * msgpack_unpacker_buffer_capacity(&pac) bytes. */ memcpy(msgpack_unpacker_buffer(&pac), input, 1); input += 1; EXPECT_TRUE(input <= eof); msgpack_unpacker_buffer_consumed(&pac, 1); while(msgpack_unpacker_next(&pac, &result) == MSGPACK_UNPACK_SUCCESS) { unpacked = 1; msgpack_object obj = result.data; msgpack_object e; switch(count++) { case 0: EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); EXPECT_EQ(1u, obj.via.u64); break; case 1: EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); EXPECT_EQ(2u, obj.via.u64); break; case 2: EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); EXPECT_EQ(3u, obj.via.u64); break; case 3: EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(std::string("str",3), std::string(obj.via.str.ptr, obj.via.str.size)); break; case 4: EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(1u, obj.via.array.size); e = obj.via.array.ptr[0]; EXPECT_EQ(MSGPACK_OBJECT_STR, e.type); EXPECT_EQ(std::string("str_data",8), std::string(e.via.str.ptr, e.via.str.size)); break; case 5: EXPECT_EQ(MSGPACK_OBJECT_BIN, obj.type); EXPECT_EQ(std::string("bin",3), std::string(obj.via.bin.ptr, obj.via.bin.size)); break; case 6: EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(1u, obj.via.array.size); e = obj.via.array.ptr[0]; EXPECT_EQ(MSGPACK_OBJECT_BIN, e.type); EXPECT_EQ(std::string("bin_data",8), std::string(e.via.bin.ptr, e.via.bin.size)); break; case 7: EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type); EXPECT_EQ(1u, obj.via.map.size); e = obj.via.map.ptr[0].key; EXPECT_EQ(MSGPACK_OBJECT_FLOAT, e.type); ASSERT_FLOAT_EQ(0.4f, static_cast(e.via.f64)); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, e.type); ASSERT_FLOAT_EQ(0.4f, static_cast(e.via.dec)); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT e = obj.via.map.ptr[0].val; EXPECT_EQ(MSGPACK_OBJECT_FLOAT, e.type); ASSERT_DOUBLE_EQ(0.8, e.via.f64); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, e.type); ASSERT_DOUBLE_EQ(0.8, e.via.dec); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT break; } } } } msgpack_unpacker_destroy(&pac); msgpack_unpacked_destroy(&result); msgpack_sbuffer_free(buffer); } TEST(streaming, basic_with_size) { int ret; size_t bytes; size_t parsed = 0; msgpack_sbuffer* buffer = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); msgpack_unpacked result; msgpack_unpacker *unp; // 1, 2, 3, "str", ["str_data"], "bin", ["bin_data"], {0.3: 0.4} msgpack_pack_int(pk, 1); msgpack_pack_int(pk, 2); msgpack_pack_int(pk, 3); msgpack_pack_str(pk, 3); msgpack_pack_str_body(pk, "str", 3); msgpack_pack_array(pk, 1); msgpack_pack_str(pk, 8); msgpack_pack_str_body(pk, "str_data", 8); msgpack_pack_bin(pk, 3); msgpack_pack_bin_body(pk, "bin", 3); msgpack_pack_array(pk, 1); msgpack_pack_bin(pk, 8); msgpack_pack_bin_body(pk, "bin_data", 8); msgpack_pack_map(pk, 1); msgpack_pack_float(pk, 0.4f); msgpack_pack_double(pk, 0.8); msgpack_packer_free(pk); unp = msgpack_unpacker_new(32 * 1024); msgpack_unpacked_init(&result); const char* input = buffer->data; while (parsed < buffer->size) { memcpy(msgpack_unpacker_buffer(unp), input, 1); msgpack_unpacker_buffer_consumed(unp, 1); input += 1; bytes = 0; ret = msgpack_unpacker_next_with_size(unp, &result, &bytes); if (ret == MSGPACK_UNPACK_CONTINUE) { EXPECT_GT(bytes, static_cast(0)); continue; } while (ret == MSGPACK_UNPACK_SUCCESS) { EXPECT_GT(bytes, static_cast(0)); parsed += bytes; ret = msgpack_unpacker_next_with_size(unp, &result, &bytes); } } EXPECT_EQ(parsed, buffer->size); msgpack_unpacked_destroy(&result); msgpack_unpacker_free(unp); msgpack_sbuffer_free(buffer); } msgpack-c-6.0.1/test/CMakeLists.txt0000644000175000017460000000256314602664033016121 0ustar kondowheelFIND_PACKAGE (GTest REQUIRED) FIND_PACKAGE (ZLIB REQUIRED) FIND_PACKAGE (Threads REQUIRED) INCLUDE_DIRECTORIES ( ${GTEST_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ) SET (check_PROGRAMS buffer_c.cpp fixint_c.cpp msgpack_c.cpp pack_unpack_c.cpp streaming_c.cpp ) FOREACH (source_file ${check_PROGRAMS}) GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) ADD_EXECUTABLE ( ${source_file_we} ${source_file} ) TARGET_LINK_LIBRARIES (${source_file_we} msgpack-c ${GTEST_BOTH_LIBRARIES} ${ZLIB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) ADD_TEST (${source_file_we} ${source_file_we}) IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -Wconversion") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE () SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") ENDIF () ENDIF () ENDFOREACH () msgpack-c-6.0.1/test/pack_unpack_c.cpp0000644000175000017460000000533414602664033016645 0ustar kondowheel#include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) #include TEST(pack, num) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); EXPECT_EQ(0, msgpack_pack_int(pk, 1)); msgpack_sbuffer_free(sbuf); msgpack_packer_free(pk); } TEST(pack, array) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); EXPECT_EQ(0, msgpack_pack_array(pk, 3)); EXPECT_EQ(0, msgpack_pack_int(pk, 1)); EXPECT_EQ(0, msgpack_pack_int(pk, 2)); EXPECT_EQ(0, msgpack_pack_int(pk, 3)); msgpack_sbuffer_free(sbuf); msgpack_packer_free(pk); } TEST(unpack, sequence) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); EXPECT_EQ(0, msgpack_pack_int(pk, 1)); EXPECT_EQ(0, msgpack_pack_int(pk, 2)); EXPECT_EQ(0, msgpack_pack_int(pk, 3)); msgpack_packer_free(pk); msgpack_unpack_return success; size_t offset = 0; msgpack_unpacked msg; msgpack_unpacked_init(&msg); success = msgpack_unpack_next(&msg, sbuf->data, sbuf->size, &offset); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, success); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, msg.data.type); EXPECT_EQ(1u, msg.data.via.u64); success = msgpack_unpack_next(&msg, sbuf->data, sbuf->size, &offset); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, success); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, msg.data.type); EXPECT_EQ(2u, msg.data.via.u64); success = msgpack_unpack_next(&msg, sbuf->data, sbuf->size, &offset); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, success); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, msg.data.type); EXPECT_EQ(3u, msg.data.via.u64); success = msgpack_unpack_next(&msg, sbuf->data, sbuf->size, &offset); EXPECT_EQ(MSGPACK_UNPACK_CONTINUE, success); msgpack_sbuffer_free(sbuf); msgpack_unpacked_destroy(&msg); } TEST(pack, insufficient) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); EXPECT_EQ(0, msgpack_pack_int(pk, 255)); // uint8 (2bytes) msgpack_unpack_return success; size_t offset = 0; msgpack_unpacked msg; msgpack_unpacked_init(&msg); success = msgpack_unpack_next(&msg, sbuf->data, 1, &offset); EXPECT_EQ(MSGPACK_UNPACK_CONTINUE, success); EXPECT_EQ(1u, offset); msgpack_unpacked_destroy(&msg); msgpack_sbuffer_free(sbuf); msgpack_packer_free(pk); } msgpack-c-6.0.1/test/msgpack_c.cpp0000644000175000017460000015710414602664033016016 0ustar kondowheel#include "msgpack.h" #include #include #include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) #if defined(_MSC_VER) || defined(__MINGW32__) #define msgpack_rand() ((double)rand() / RAND_MAX) #else // _MSC_VER || __MINGW32__ #define msgpack_rand() drand48() #endif // _MSC_VER || __MINGW32__ #if defined(_MSC_VER) #define msgpack_snprintf sprintf_s #else // _MSC_VER #define msgpack_snprintf snprintf #endif // _MSC_VER using namespace std; const unsigned int kLoop = 10000; const double kEPS = 1e-10; #define GEN_TEST_SIGNED(test_type, func_type) \ do { \ vector v; \ v.push_back(0); \ v.push_back(1); \ v.push_back(-1); \ v.push_back(numeric_limits::min()); \ v.push_back(numeric_limits::max()); \ for (unsigned int i = 0; i < kLoop; i++) \ v.push_back(static_cast(rand())); \ for (unsigned int i = 0; i < v.size() ; i++) { \ test_type val = v[i]; \ msgpack_sbuffer sbuf; \ msgpack_sbuffer_init(&sbuf); \ msgpack_packer pk; \ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); \ msgpack_pack_##func_type(&pk, val); \ msgpack_zone z; \ msgpack_zone_init(&z, 2048); \ msgpack_object obj; \ msgpack_unpack_return ret = \ msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); \ EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); \ if (val < 0) { \ EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, obj.type); \ EXPECT_EQ(val, obj.via.i64); \ } else { \ EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); \ EXPECT_EQ(static_cast(val), obj.via.u64); \ } \ msgpack_zone_destroy(&z); \ msgpack_sbuffer_destroy(&sbuf); \ } \ } while(0) #define GEN_TEST_UNSIGNED(test_type, func_type) \ do { \ vector v; \ v.push_back(0); \ v.push_back(1); \ v.push_back(2); \ v.push_back(numeric_limits::min()); \ v.push_back(numeric_limits::max()); \ for (unsigned int i = 0; i < kLoop; i++) \ v.push_back(static_cast(rand())); \ for (unsigned int i = 0; i < v.size() ; i++) { \ test_type val = v[i]; \ msgpack_sbuffer sbuf; \ msgpack_sbuffer_init(&sbuf); \ msgpack_packer pk; \ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); \ msgpack_pack_##func_type(&pk, val); \ msgpack_zone z; \ msgpack_zone_init(&z, 2048); \ msgpack_object obj; \ msgpack_unpack_return ret = \ msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); \ EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); \ EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); \ EXPECT_EQ(val, obj.via.u64); \ msgpack_zone_destroy(&z); \ msgpack_sbuffer_destroy(&sbuf); \ } \ } while(0) TEST(MSGPACKC, simple_buffer_char) { #if defined(CHAR_MIN) #if CHAR_MIN < 0 GEN_TEST_SIGNED(char, char); #else GEN_TEST_UNSIGNED(char, char); #endif #else #error CHAR_MIN is not defined #endif } TEST(MSGPACKC, simple_buffer_singed_char) { GEN_TEST_SIGNED(signed char, signed_char); } TEST(MSGPACKC, simple_buffer_short) { GEN_TEST_SIGNED(short, short); } TEST(MSGPACKC, simple_buffer_int) { GEN_TEST_SIGNED(int, int); } TEST(MSGPACKC, simple_buffer_long) { GEN_TEST_SIGNED(long, long); } TEST(MSGPACKC, simple_buffer_long_long) { GEN_TEST_SIGNED(long long, long_long); } TEST(MSGPACKC, simple_buffer_unsigned_char) { GEN_TEST_UNSIGNED(unsigned char, unsigned_char); } TEST(MSGPACKC, simple_buffer_unsigned_short) { GEN_TEST_UNSIGNED(unsigned short, unsigned_short); } TEST(MSGPACKC, simple_buffer_unsigned_int) { GEN_TEST_UNSIGNED(unsigned int, unsigned_int); } TEST(MSGPACKC, simple_buffer_unsigned_long) { GEN_TEST_UNSIGNED(unsigned long, unsigned_long); } TEST(MSGPACKC, simple_buffer_unsigned_long_long) { GEN_TEST_UNSIGNED(unsigned long long, unsigned_long_long); } TEST(MSGPACKC, simple_buffer_uint8) { GEN_TEST_UNSIGNED(uint8_t, uint8); } TEST(MSGPACKC, simple_buffer_uint16) { GEN_TEST_UNSIGNED(uint16_t, uint16); } TEST(MSGPACKC, simple_buffer_uint32) { GEN_TEST_UNSIGNED(uint32_t, uint32); } TEST(MSGPACKC, simple_buffer_uint64) { GEN_TEST_UNSIGNED(uint64_t, uint64); } TEST(MSGPACKC, simple_buffer_int8) { GEN_TEST_SIGNED(int8_t, int8); } TEST(MSGPACKC, simple_buffer_int16) { GEN_TEST_SIGNED(int16_t, int16); } TEST(MSGPACKC, simple_buffer_int32) { GEN_TEST_SIGNED(int32_t, int32); } TEST(MSGPACKC, simple_buffer_int64) { GEN_TEST_SIGNED(int64_t, int64); } #if !defined(_MSC_VER) || _MSC_VER >=1800 TEST(MSGPACKC, simple_buffer_float) { vector v; v.push_back(0.0); v.push_back(1.0); v.push_back(-1.0); v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nanf("tag")); if (numeric_limits::has_infinity) { v.push_back(numeric_limits::infinity()); v.push_back(-numeric_limits::infinity()); } if (numeric_limits::has_quiet_NaN) { v.push_back(numeric_limits::quiet_NaN()); } if (numeric_limits::has_signaling_NaN) { v.push_back(numeric_limits::signaling_NaN()); } for (unsigned int i = 0; i < kLoop; i++) { v.push_back(static_cast(msgpack_rand())); v.push_back(static_cast(-msgpack_rand())); } for (unsigned int i = 0; i < v.size() ; i++) { float val = v[i]; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_float(&pk, val); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_FLOAT32, obj.type); if (isnan(val)) { EXPECT_TRUE(isnan(obj.via.f64)); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(isnan(obj.via.dec)); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } else if (isinf(val)) { EXPECT_TRUE(isinf(obj.via.f64)); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(isinf(obj.via.dec)); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } else { EXPECT_TRUE(fabs(obj.via.f64 - val) <= kEPS); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(fabs(obj.via.dec - val) <= kEPS); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } } TEST(MSGPACKC, simple_buffer_double) { vector v; v.push_back(0.0); v.push_back(-0.0); v.push_back(1.0); v.push_back(-1.0); v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nan("tag")); if (numeric_limits::has_infinity) { v.push_back(numeric_limits::infinity()); v.push_back(-numeric_limits::infinity()); } if (numeric_limits::has_quiet_NaN) { v.push_back(numeric_limits::quiet_NaN()); } if (numeric_limits::has_signaling_NaN) { v.push_back(numeric_limits::signaling_NaN()); } for (unsigned int i = 0; i < kLoop; i++) { v.push_back(msgpack_rand()); v.push_back(-msgpack_rand()); } for (unsigned int i = 0; i < v.size() ; i++) { double val = v[i]; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_double(&pk, val); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_FLOAT64, obj.type); EXPECT_EQ(MSGPACK_OBJECT_FLOAT, obj.type); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, obj.type); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT if (isnan(val)) { EXPECT_TRUE(isnan(obj.via.f64)); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(isnan(obj.via.dec)); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } else if (isinf(val)) { EXPECT_TRUE(isinf(obj.via.f64)); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(isinf(obj.via.dec)); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } else { EXPECT_TRUE(fabs(obj.via.f64 - val) <= kEPS); #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) EXPECT_TRUE(fabs(obj.via.dec - val) <= kEPS); #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT } msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } } #endif // !defined(_MSC_VER) || _MSC_VER >=1800 TEST(MSGPACKC, simple_buffer_nil) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_nil(&pk); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_NIL, obj.type); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_true) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_true(&pk); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type); EXPECT_EQ(true, obj.via.boolean); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_false) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_false(&pk); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type); EXPECT_FALSE(obj.via.boolean); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext1) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); char const buf[] = { 2 }; msgpack_pack_ext(&pk, sizeof(buf), 1); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(1u, obj.via.ext.size); EXPECT_EQ(1, obj.via.ext.type); EXPECT_EQ(2, obj.via.ext.ptr[0]); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext2) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); char const buf[] = { 2, 3 }; msgpack_pack_ext(&pk, sizeof(buf), 0); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(2u, obj.via.ext.size); EXPECT_EQ(0, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext4) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); char const buf[] = { 2, 3, 4, 5 }; msgpack_pack_ext(&pk, sizeof(buf), 1); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(4u, obj.via.ext.size); EXPECT_EQ(1, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext8) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); char const buf [] = { 2, 3, 4, 5, 6, 7, 8, 9 }; msgpack_pack_ext(&pk, sizeof(buf), 1); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(8u, obj.via.ext.size); EXPECT_EQ(1, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext16) { msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); char const buf [] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; msgpack_pack_ext(&pk, sizeof(buf), 1); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(16u, obj.via.ext.size); EXPECT_EQ(1, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext_1byte_0) { const size_t size = 0; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_ext(&pk, size, 77); // fprintf(stderr, "size: %u, data: \"", sbuf.size); // for (size_t i = 0; i < sbuf.size; i++) // fprintf(stderr, "%02x ", (uint8_t)sbuf.data[i]); // fprintf(stderr, "\"\n"); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(size, obj.via.ext.size); EXPECT_EQ(77, obj.via.ext.type); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext_1byte_255) { const size_t size = 255; char buf[size]; for (size_t i = 0; i != size; ++i) buf[i] = (char)i; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_ext(&pk, size, 78); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(size, obj.via.ext.size); EXPECT_EQ(78, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext_2byte_256) { const size_t size = 256; char buf[size]; for (size_t i = 0; i != size; ++i) buf[i] = (char)i; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_ext(&pk, size, 79); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(size, obj.via.ext.size); EXPECT_EQ(79, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext_2byte_65535) { const size_t size = 65535; char buf[size]; for (size_t i = 0; i != size; ++i) buf[i] = (char)i; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_ext(&pk, size, 80); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(size, obj.via.ext.size); EXPECT_EQ(80, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_fixext_4byte_65536) { const size_t size = 65536; char buf[size]; for (size_t i = 0; i != size; ++i) buf[i] = (char)i; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_ext(&pk, size, 81); msgpack_pack_ext_body(&pk, buf, sizeof(buf)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(size, obj.via.ext.size); EXPECT_EQ(81, obj.via.ext.type); EXPECT_EQ(0, memcmp(buf, obj.via.ext.ptr, sizeof(buf))); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_timestamp_32) { msgpack_timestamp ts = { 0xffffffff, 0 }; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_timestamp(&pk, &ts); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(4u, obj.via.ext.size); EXPECT_EQ(-1, obj.via.ext.type); msgpack_timestamp ts2; bool r = msgpack_object_to_timestamp(&obj, &ts2); EXPECT_TRUE(r); EXPECT_EQ(ts.tv_sec, ts2.tv_sec); EXPECT_EQ(ts.tv_nsec, ts2.tv_nsec); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_timestamp_64) { msgpack_timestamp ts = { 0x3ffffffffL, 999999999 }; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_timestamp(&pk, &ts); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(8u, obj.via.ext.size); EXPECT_EQ(-1, obj.via.ext.type); msgpack_timestamp ts2; bool r = msgpack_object_to_timestamp(&obj, &ts2); EXPECT_TRUE(r); EXPECT_EQ(ts.tv_sec, ts2.tv_sec); EXPECT_EQ(ts.tv_nsec, ts2.tv_nsec); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_timestamp_96) { msgpack_timestamp ts = { 0x7fffffffffffffffLL, 999999999 }; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_timestamp(&pk, &ts); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(12u, obj.via.ext.size); EXPECT_EQ(-1, obj.via.ext.type); msgpack_timestamp ts2; bool r = msgpack_object_to_timestamp(&obj, &ts2); EXPECT_TRUE(r); EXPECT_EQ(ts.tv_sec, ts2.tv_sec); EXPECT_EQ(ts.tv_nsec, ts2.tv_nsec); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_array) { unsigned int array_size = 5; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, array_size); msgpack_pack_nil(&pk); msgpack_pack_true(&pk); msgpack_pack_false(&pk); msgpack_pack_int(&pk, 10); msgpack_pack_int(&pk, -10); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(array_size, obj.via.array.size); for (unsigned int i = 0; i < obj.via.array.size; i++) { msgpack_object o = obj.via.array.ptr[i]; switch (i) { case 0: EXPECT_EQ(MSGPACK_OBJECT_NIL, o.type); break; case 1: EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, o.type); EXPECT_EQ(true, o.via.boolean); break; case 2: EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, o.type); EXPECT_FALSE(o.via.boolean); break; case 3: EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, o.type); EXPECT_EQ(10u, o.via.u64); break; case 4: EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, o.type); EXPECT_EQ(-10, o.via.i64); break; } } msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_map) { unsigned int map_size = 2; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_map(&pk, map_size); msgpack_pack_true(&pk); msgpack_pack_false(&pk); msgpack_pack_int(&pk, 10); msgpack_pack_int(&pk, -10); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type); EXPECT_EQ(map_size, obj.via.map.size); for (unsigned int i = 0; i < map_size; i++) { msgpack_object key = obj.via.map.ptr[i].key; msgpack_object val = obj.via.map.ptr[i].val; switch (i) { case 0: EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, key.type); EXPECT_EQ(true, key.via.boolean); EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, val.type); EXPECT_FALSE(val.via.boolean); break; case 1: EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, key.type); EXPECT_EQ(10u, key.via.u64); EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, val.type); EXPECT_EQ(-10, val.via.i64); break; } } msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str) { unsigned int str_size = 7; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, "fr", 2); msgpack_pack_str_body(&pk, "syuki", 5); // invalid data msgpack_pack_str_body(&pk, "", 0); msgpack_pack_str_body(&pk, "kzk", 0); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_fix_l) { char const* str = NULL; unsigned int str_size = 0; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x01u); EXPECT_EQ(sbuf.data[0], static_cast(0xa0u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_fix_h) { char str[0x1f] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x1f+1u); EXPECT_EQ(sbuf.data[0], static_cast(0xbfu)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_8_l) { char str[0x1f+1] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x1f+1+2u); EXPECT_EQ(sbuf.data[0], static_cast(0xd9u)); EXPECT_EQ(sbuf.data[1], static_cast(0x20u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_8_h) { char str[0xff] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xff+2u); EXPECT_EQ(sbuf.data[0], static_cast(0xd9u)); EXPECT_EQ(sbuf.data[1], static_cast(0xffu)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_16_l) { char str[0xff+1] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xff+1+3u); EXPECT_EQ(sbuf.data[0], static_cast(0xdau)); EXPECT_EQ(sbuf.data[1], static_cast(0x01u)); EXPECT_EQ(sbuf.data[2], static_cast(0x00u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_16_h) { char str[0xffff] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xffff+3u); EXPECT_EQ(sbuf.data[0], static_cast(0xdau)); EXPECT_EQ(sbuf.data[1], static_cast(0xffu)); EXPECT_EQ(sbuf.data[2], static_cast(0xffu)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_str_32_l) { char str[0xffff+1] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xffff+1+5u); EXPECT_EQ(sbuf.data[0], static_cast(0xdbu)); EXPECT_EQ(sbuf.data[1], static_cast(0x00u)); EXPECT_EQ(sbuf.data[2], static_cast(0x01u)); EXPECT_EQ(sbuf.data[3], static_cast(0x00u)); EXPECT_EQ(sbuf.data[4], static_cast(0x00u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_v4raw_fix_l) { char const* str = NULL; unsigned int str_size = 0; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_v4raw(&pk, str_size); msgpack_pack_v4raw_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x01u); EXPECT_EQ(sbuf.data[0], static_cast(0xa0u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_v4raw_fix_h) { char str[0x1f] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_v4raw(&pk, str_size); msgpack_pack_v4raw_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x1f+1u); EXPECT_EQ(sbuf.data[0], static_cast(0xbfu)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_v4raw_16_l) { char str[0x1f+1] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_v4raw(&pk, str_size); msgpack_pack_v4raw_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0x1f+1+3u); EXPECT_EQ(sbuf.data[0], static_cast(0xdau)); EXPECT_EQ(sbuf.data[1], static_cast(0x00u)); EXPECT_EQ(sbuf.data[2], static_cast(0x20u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_v4raw_16_h) { char str[0xffff] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_v4raw(&pk, str_size); msgpack_pack_v4raw_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xffff+3u); EXPECT_EQ(sbuf.data[0], static_cast(0xdau)); EXPECT_EQ(sbuf.data[1], static_cast(0xffu)); EXPECT_EQ(sbuf.data[2], static_cast(0xffu)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_buffer_v4raw_32_l) { char str[0xffff+1] = {'0'}; unsigned int str_size = sizeof(str); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_v4raw(&pk, str_size); msgpack_pack_v4raw_body(&pk, str, str_size); EXPECT_EQ(sbuf.size, 0xffff+1+5u); EXPECT_EQ(sbuf.data[0], static_cast(0xdbu)); EXPECT_EQ(sbuf.data[1], static_cast(0x00u)); EXPECT_EQ(sbuf.data[2], static_cast(0x01u)); EXPECT_EQ(sbuf.data[3], static_cast(0x00u)); EXPECT_EQ(sbuf.data[4], static_cast(0x00u)); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp(str, obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_object_print_buffer_str_empty) { unsigned int str_size = 0; char buffer[64]; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, "", str_size); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); msgpack_object_print_buffer(buffer, sizeof(buffer) - 1, obj); EXPECT_STREQ("\"\"", buffer); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_object_print_buffer_array_str) { const char * str = "hello"; const size_t str_size = strlen(str); const unsigned int array_size = 1; char expected[64]; char buffer[64]; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, array_size); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, str, str_size); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(array_size, obj.via.array.size); msgpack_object o = *obj.via.array.ptr; EXPECT_EQ(MSGPACK_OBJECT_STR, o.type); EXPECT_EQ(str_size, o.via.str.size); EXPECT_EQ(0, memcmp(str, o.via.str.ptr, str_size)); msgpack_snprintf(expected, sizeof(expected), "[\"%s\"]", str); expected[sizeof(expected) - 1] = '\0'; // not needed w/ sprintf_s msgpack_object_print_buffer(buffer, sizeof(buffer) - 1, obj); EXPECT_STREQ(expected, buffer); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_object_print_buffer_array_str_empty) { const unsigned int array_size = 1; const unsigned int str_size = 0; char buffer[64]; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, array_size); msgpack_pack_str(&pk, str_size); msgpack_pack_str_body(&pk, "", 0); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(array_size, obj.via.array.size); msgpack_object o = *obj.via.array.ptr; EXPECT_EQ(MSGPACK_OBJECT_STR, o.type); EXPECT_EQ(str_size, o.via.str.size); msgpack_object_print_buffer(buffer, sizeof(buffer) - 1, obj); EXPECT_STREQ("[\"\"]", buffer); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_object_print_buffer_map_str) { const char * mkey = "key"; const char * mval = "value"; char expected[64]; char buffer[64]; const size_t mkey_size = strlen(mkey);; const size_t mval_size = strlen(mval); const unsigned int map_size = 1; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_map(&pk, map_size); msgpack_pack_str(&pk, mkey_size); msgpack_pack_str_body(&pk, mkey, mkey_size); msgpack_pack_str(&pk, mval_size); msgpack_pack_str_body(&pk, mval, mval_size); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type); EXPECT_EQ(map_size, obj.via.map.size); msgpack_object key = obj.via.map.ptr->key; msgpack_object val = obj.via.map.ptr->val; EXPECT_EQ(MSGPACK_OBJECT_STR, key.type); EXPECT_EQ(mkey_size, key.via.str.size); EXPECT_EQ(0, memcmp(mkey, key.via.str.ptr, mkey_size)); EXPECT_EQ(MSGPACK_OBJECT_STR, val.type); EXPECT_EQ(mval_size, val.via.str.size); EXPECT_EQ(0, memcmp(mval, val.via.str.ptr, mval_size)); msgpack_snprintf(expected, sizeof(expected), "{\"%s\"=>\"%s\"}", mkey, mval); expected[sizeof(expected) - 1] = '\0'; // not needed w/ sprintf_s msgpack_object_print_buffer(buffer, sizeof(buffer) - 1, obj); EXPECT_STREQ(expected, buffer); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, simple_object_print_buffer_map_str_empty) { const char * mkey = "key"; char expected[64]; char buffer[64]; const size_t mkey_size = strlen(mkey);; const unsigned int map_size = 1; msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_map(&pk, map_size); msgpack_pack_str(&pk, mkey_size); msgpack_pack_str_body(&pk, mkey, mkey_size); msgpack_pack_str(&pk, 0); msgpack_pack_str_body(&pk, "", 0); msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type); EXPECT_EQ(map_size, obj.via.map.size); msgpack_object key = obj.via.map.ptr->key; msgpack_object val = obj.via.map.ptr->val; EXPECT_EQ(MSGPACK_OBJECT_STR, key.type); EXPECT_EQ(mkey_size, key.via.str.size); EXPECT_EQ(0, memcmp(mkey, key.via.str.ptr, mkey_size)); EXPECT_EQ(MSGPACK_OBJECT_STR, val.type); EXPECT_EQ(0UL, val.via.str.size); msgpack_snprintf(expected, sizeof(expected), "{\"%s\"=>\"\"}", mkey); expected[sizeof(expected) - 1] = '\0'; // not needed w/ sprintf_s msgpack_object_print_buffer(buffer, sizeof(buffer) - 1, obj); EXPECT_STREQ(expected, buffer); msgpack_zone_destroy(&z); msgpack_sbuffer_destroy(&sbuf); } TEST(MSGPACKC, unpack_fixstr) { size_t str_size = 7; const char buf[] = { (char)0xa7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_str8) { size_t str_size = 7; const char buf[] = { (char)0xd9, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_str16) { size_t str_size = 7; const char buf[] = { (char)0xda, 0, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_str32) { size_t str_size = 7; const char buf[] = { (char)0xdb, 0, 0, 0, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(str_size, obj.via.str.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.str.ptr, str_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_bin8) { size_t bin_size = 7; const char buf[] = { (char)0xc4, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_BIN, obj.type); EXPECT_EQ(bin_size, obj.via.bin.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.bin.ptr, bin_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_bin16) { size_t bin_size = 7; const char buf[] = { (char)0xc5, 0, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_BIN, obj.type); EXPECT_EQ(bin_size, obj.via.bin.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.bin.ptr, bin_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_bin32) { size_t bin_size = 7; const char buf[] = { (char)0xc6, 0, 0, 0, 7, 'f', 'r', 's', 'y', 'u', 'k', 'i' }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_BIN, obj.type); EXPECT_EQ(bin_size, obj.via.bin.size); EXPECT_EQ(0, memcmp("frsyuki", obj.via.bin.ptr, bin_size)); msgpack_zone_destroy(&z); } TEST(MSGPACKC, unpack_array_uint64) { const char buf[] = { (char)0x91, (char)0xcf, (char)0xff, (char)0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; msgpack_zone z; msgpack_zone_init(&z, 2048); msgpack_object obj; msgpack_unpack_return ret; ret = msgpack_unpack(buf, sizeof(buf), NULL, &z, &obj); EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(1u, obj.via.array.size); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.via.array.ptr[0].type); EXPECT_EQ(0xFFF0000000000001LL, obj.via.array.ptr[0].via.u64); msgpack_zone_destroy(&z); } TEST(MSGPACKC, vref_buffer_overflow) { msgpack_vrefbuffer vbuf; msgpack_vrefbuffer to; size_t ref_size = 0; size_t chunk_size = std::numeric_limits::max(); EXPECT_FALSE(msgpack_vrefbuffer_init(&vbuf, ref_size, chunk_size)); EXPECT_EQ(-1, msgpack_vrefbuffer_migrate(&vbuf, &to)); } TEST(MSGPACKC, object_print_buffer_overflow) { msgpack_object obj; obj.type = MSGPACK_OBJECT_NIL; char buffer[4]; int ret; ret = msgpack_object_print_buffer(buffer, 1, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 2, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 3, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 4, obj); EXPECT_EQ(3, ret); EXPECT_STREQ("nil", buffer); } TEST(MSGPACKC, object_bin_print_buffer_overflow) { msgpack_object obj; obj.type = MSGPACK_OBJECT_BIN; obj.via.bin.ptr = "test"; obj.via.bin.size = 4; char buffer[7]; int ret; ret = msgpack_object_print_buffer(buffer, 1, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 2, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 3, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 4, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 5, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 6, obj); EXPECT_EQ(0, ret); ret = msgpack_object_print_buffer(buffer, 7, obj); EXPECT_EQ(6, ret); EXPECT_STREQ("\"test\"", buffer); } /* test for vrefbuffer */ #define GEN_TEST_VREFBUFFER_PREPARE(...) \ msgpack_vrefbuffer vbuf; \ msgpack_packer pk; \ const msgpack_iovec *iov; \ size_t iovcnt, len = 0, i; \ char buf[1024]; \ msgpack_vrefbuffer_init(&vbuf, 0, 0); \ msgpack_packer_init(&pk, &vbuf, msgpack_vrefbuffer_write); \ __VA_ARGS__; \ iov = msgpack_vrefbuffer_vec(&vbuf); \ iovcnt = msgpack_vrefbuffer_veclen(&vbuf); \ for (i = 0; i < iovcnt; i++) { \ memcpy(buf + len, iov[i].iov_base, iov[i].iov_len); \ len += iov[i].iov_len; \ } \ msgpack_vrefbuffer_destroy(&vbuf) #define GEN_TEST_VREFBUFFER_CHECK(...) \ msgpack_object obj; \ msgpack_unpack_return ret; \ msgpack_zone z; \ msgpack_zone_init(&z, 2048); \ ret = msgpack_unpack(buf, len, NULL, &z, &obj); \ EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); \ __VA_ARGS__; \ msgpack_zone_destroy(&z) TEST(buffer, vrefbuffer_uint8) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_uint8(&pk, 32)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); EXPECT_EQ(32U, obj.via.u64)); } TEST(buffer, vrefbuffer_int8) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_int8(&pk, -32)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, obj.type); EXPECT_EQ(-32, obj.via.i64)); } TEST(buffer, vrefbuffer_float32) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_float(&pk, 1.0)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_FLOAT32, obj.type); EXPECT_EQ(1.0, obj.via.f64)); } TEST(buffer, vrefbuffer_float64) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_double(&pk, 1.0)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_FLOAT64, obj.type); EXPECT_EQ(1.0, obj.via.f64)); } TEST(buffer, vrefbuffer_nil) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_nil(&pk)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_NIL, obj.type)); } TEST(buffer, vrefbuffer_false) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_false(&pk)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type); EXPECT_FALSE(obj.via.boolean)); } TEST(buffer, vrefbuffer_true) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_true(&pk)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type); EXPECT_TRUE(obj.via.boolean)); } #define TEST_VBUF_RAW_LEN 30U char test_vbuf_raw[TEST_VBUF_RAW_LEN] = "frsyuki"; TEST(buffer, vrefbuffer_str) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_str(&pk, TEST_VBUF_RAW_LEN); msgpack_pack_str_body(&pk, test_vbuf_raw, TEST_VBUF_RAW_LEN)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_STR, obj.type); EXPECT_EQ(TEST_VBUF_RAW_LEN, obj.via.str.size); EXPECT_EQ(0, memcmp(test_vbuf_raw, obj.via.str.ptr, 30))); } TEST(buffer, vrefbuffer_bin) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_bin(&pk, TEST_VBUF_RAW_LEN); msgpack_pack_bin_body(&pk, test_vbuf_raw, TEST_VBUF_RAW_LEN)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(TEST_VBUF_RAW_LEN, obj.via.bin.size); EXPECT_EQ(0, memcmp(test_vbuf_raw, obj.via.bin.ptr, TEST_VBUF_RAW_LEN))); } TEST(buffer, vrefbuffer_ext) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_ext(&pk, TEST_VBUF_RAW_LEN, 127); msgpack_pack_ext_body(&pk, test_vbuf_raw, TEST_VBUF_RAW_LEN)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_EXT, obj.type); EXPECT_EQ(TEST_VBUF_RAW_LEN, obj.via.ext.size); EXPECT_EQ(0, memcmp(test_vbuf_raw, obj.via.ext.ptr, TEST_VBUF_RAW_LEN))); } TEST(buffer, vrefbuffer_array) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_array(&pk, 2); msgpack_pack_int(&pk, 3); msgpack_pack_int(&pk, 4)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type); EXPECT_EQ(2U, obj.via.array.size); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.via.array.ptr[0].type); EXPECT_EQ(3U, obj.via.array.ptr[0].via.u64); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.via.array.ptr[1].type); EXPECT_EQ(4U, obj.via.array.ptr[1].via.u64)); } TEST(buffer, vrefbuffer_map) { GEN_TEST_VREFBUFFER_PREPARE( msgpack_pack_map(&pk, 1); msgpack_pack_int(&pk, 2); msgpack_pack_int(&pk, 3)); GEN_TEST_VREFBUFFER_CHECK( EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type); EXPECT_EQ(1U, obj.via.map.size); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.via.map.ptr[0].key.type); EXPECT_EQ(2U, obj.via.map.ptr[0].key.via.u64); EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.via.map.ptr[0].val.type); EXPECT_EQ(3U, obj.via.map.ptr[0].val.via.u64)); } msgpack-c-6.0.1/include/0000755000175000017460000000000014602664033014017 5ustar kondowheelmsgpack-c-6.0.1/include/msgpack.h0000644000175000017460000000101614602664033015613 0ustar kondowheel/* * MessagePack for C * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ /** * @defgroup msgpack MessagePack C * @{ * @} */ #include "msgpack/util.h" #include "msgpack/object.h" #include "msgpack/zone.h" #include "msgpack/pack.h" #include "msgpack/unpack.h" #include "msgpack/sbuffer.h" #include "msgpack/vrefbuffer.h" #include "msgpack/version.h" msgpack-c-6.0.1/include/msgpack/0000755000175000017460000000000014602712217015442 5ustar kondowheelmsgpack-c-6.0.1/include/msgpack/fbuffer.h0000644000175000017460000000135614602664033017241 0ustar kondowheel/* * MessagePack for C FILE* buffer adaptor * * Copyright (C) 2013 Vladimir Volodko * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_FBUFFER_H #define MSGPACK_FBUFFER_H #include #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_fbuffer FILE* buffer * @ingroup msgpack_buffer * @{ */ static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len) { assert(buf || len == 0); if(!buf) return 0; return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; } /** @} */ #ifdef __cplusplus } #endif #endif /* msgpack/fbuffer.h */ msgpack-c-6.0.1/include/msgpack/unpack.h0000644000175000017460000001724614602664033017110 0ustar kondowheel/* * MessagePack for C unpacking routine * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_UNPACKER_H #define MSGPACK_UNPACKER_H #include "zone.h" #include "object.h" #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_unpack Deserializer * @ingroup msgpack * @{ */ typedef struct msgpack_unpacked { msgpack_zone* zone; msgpack_object data; } msgpack_unpacked; typedef enum { MSGPACK_UNPACK_SUCCESS = 2, MSGPACK_UNPACK_EXTRA_BYTES = 1, MSGPACK_UNPACK_CONTINUE = 0, MSGPACK_UNPACK_PARSE_ERROR = -1, MSGPACK_UNPACK_NOMEM_ERROR = -2 } msgpack_unpack_return; MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off); /** @} */ /** * @defgroup msgpack_unpacker Streaming deserializer * @ingroup msgpack * @{ */ typedef struct msgpack_unpacker { char* buffer; size_t used; size_t free; size_t off; size_t parsed; msgpack_zone* z; size_t initial_buffer_size; void* ctx; } msgpack_unpacker; #ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE #define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024) #endif /** * Initializes a streaming deserializer. * The initialized deserializer must be destroyed by msgpack_unpacker_destroy(msgpack_unpacker*). */ MSGPACK_DLLEXPORT bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size); /** * Destroys a streaming deserializer initialized by msgpack_unpacker_init(msgpack_unpacker*, size_t). */ MSGPACK_DLLEXPORT void msgpack_unpacker_destroy(msgpack_unpacker* mpac); /** * Creates a streaming deserializer. * The created deserializer must be destroyed by msgpack_unpacker_free(msgpack_unpacker*). */ MSGPACK_DLLEXPORT msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size); /** * Frees a streaming deserializer created by msgpack_unpacker_new(size_t). */ MSGPACK_DLLEXPORT void msgpack_unpacker_free(msgpack_unpacker* mpac); #ifndef MSGPACK_UNPACKER_RESERVE_SIZE #define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024) #endif /** * Reserves free space of the internal buffer. * Use this function to fill the internal buffer with * msgpack_unpacker_buffer(msgpack_unpacker*), * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). */ static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size); /** * Gets pointer to the free space of the internal buffer. * Use this function to fill the internal buffer with * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). */ static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac); /** * Gets size of the free space of the internal buffer. * Use this function to fill the internal buffer with * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), * msgpack_unpacker_buffer(const msgpack_unpacker*) and * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). */ static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac); /** * Notifies the deserializer that the internal buffer filled. * Use this function to fill the internal buffer with * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), * msgpack_unpacker_buffer(msgpack_unpacker*) and * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*). */ static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size); /** * Deserializes one object. * Returns true if it successes. Otherwise false is returned. * @param pac pointer to an initialized msgpack_unpacked object. */ MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac); /** * Deserializes one object and set the number of parsed bytes involved. * Returns true if it successes. Otherwise false is returned. * @param mpac pointer to an initialized msgpack_unpacker object. * @param result pointer to an initialized msgpack_unpacked object. * @param p_bytes pointer to variable that will be set with the number of parsed bytes. */ MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpacker_next_with_size(msgpack_unpacker* mpac, msgpack_unpacked* result, size_t *p_bytes); /** * Initializes a msgpack_unpacked object. * The initialized object must be destroyed by msgpack_unpacked_destroy(msgpack_unpacker*). * Use the object with msgpack_unpacker_next(msgpack_unpacker*, msgpack_unpacked*) or * msgpack_unpack_next(msgpack_unpacked*, const char*, size_t, size_t*). */ static inline void msgpack_unpacked_init(msgpack_unpacked* result); /** * Destroys a streaming deserializer initialized by msgpack_unpacked(). */ static inline void msgpack_unpacked_destroy(msgpack_unpacked* result); /** * Releases the memory zone from msgpack_unpacked object. * The released zone must be freed by msgpack_zone_free(msgpack_zone*). */ static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result); MSGPACK_DLLEXPORT int msgpack_unpacker_execute(msgpack_unpacker* mpac); MSGPACK_DLLEXPORT msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac); MSGPACK_DLLEXPORT msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac); MSGPACK_DLLEXPORT void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac); MSGPACK_DLLEXPORT void msgpack_unpacker_reset(msgpack_unpacker* mpac); static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac); /** @} */ // obsolete MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpack(const char* data, size_t len, size_t* off, msgpack_zone* result_zone, msgpack_object* result); static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac); MSGPACK_DLLEXPORT bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac); MSGPACK_DLLEXPORT bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size); static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size) { if(mpac->free >= size) { return true; } return msgpack_unpacker_expand_buffer(mpac, size); } static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac) { return mpac->buffer + mpac->used; } static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac) { return mpac->free; } static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size) { mpac->used += size; mpac->free -= size; } static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac) { return mpac->parsed - mpac->off + mpac->used; } static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac) { return mpac->parsed; } static inline void msgpack_unpacked_init(msgpack_unpacked* result) { memset(result, 0, sizeof(msgpack_unpacked)); } static inline void msgpack_unpacked_destroy(msgpack_unpacked* result) { if(result->zone != NULL) { msgpack_zone_free(result->zone); result->zone = NULL; memset(&result->data, 0, sizeof(msgpack_object)); } } static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result) { if(result->zone != NULL) { msgpack_zone* z = result->zone; result->zone = NULL; return z; } return NULL; } #ifdef __cplusplus } #endif #endif /* msgpack/unpack.h */ msgpack-c-6.0.1/include/msgpack/zone.h0000644000175000017460000000752314602664033016577 0ustar kondowheel/* * MessagePack for C memory pool implementation * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_ZONE_H #define MSGPACK_ZONE_H #include "sysdep.h" #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_zone Memory zone * @ingroup msgpack * @{ */ typedef struct msgpack_zone_finalizer { void (*func)(void* data); void* data; } msgpack_zone_finalizer; typedef struct msgpack_zone_finalizer_array { msgpack_zone_finalizer* tail; msgpack_zone_finalizer* end; msgpack_zone_finalizer* array; } msgpack_zone_finalizer_array; struct msgpack_zone_chunk; typedef struct msgpack_zone_chunk msgpack_zone_chunk; typedef struct msgpack_zone_chunk_list { size_t free; char* ptr; msgpack_zone_chunk* head; } msgpack_zone_chunk_list; typedef struct msgpack_zone { msgpack_zone_chunk_list chunk_list; msgpack_zone_finalizer_array finalizer_array; size_t chunk_size; } msgpack_zone; #ifndef MSGPACK_ZONE_CHUNK_SIZE #define MSGPACK_ZONE_CHUNK_SIZE 8192 #endif MSGPACK_DLLEXPORT bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size); MSGPACK_DLLEXPORT void msgpack_zone_destroy(msgpack_zone* zone); MSGPACK_DLLEXPORT msgpack_zone* msgpack_zone_new(size_t chunk_size); MSGPACK_DLLEXPORT void msgpack_zone_free(msgpack_zone* zone); static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size); static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size); static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, void (*func)(void* data), void* data); static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b); MSGPACK_DLLEXPORT bool msgpack_zone_is_empty(msgpack_zone* zone); MSGPACK_DLLEXPORT void msgpack_zone_clear(msgpack_zone* zone); /** @} */ #ifndef MSGPACK_ZONE_ALIGN #define MSGPACK_ZONE_ALIGN sizeof(void*) #endif MSGPACK_DLLEXPORT void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size); static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size) { char* ptr; msgpack_zone_chunk_list* cl = &zone->chunk_list; if(zone->chunk_list.free < size) { return msgpack_zone_malloc_expand(zone, size); } ptr = cl->ptr; cl->free -= size; cl->ptr += size; return ptr; } static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size) { char* aligned = (char*)( (uintptr_t)( zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1) ) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1) ); size_t adjusted_size = size + (size_t)(aligned - zone->chunk_list.ptr); if(zone->chunk_list.free >= adjusted_size) { zone->chunk_list.free -= adjusted_size; zone->chunk_list.ptr += adjusted_size; return aligned; } { void* ptr = msgpack_zone_malloc_expand(zone, size + (MSGPACK_ZONE_ALIGN - 1)); if (ptr) { return (char*)((uintptr_t)(ptr) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1)); } } return NULL; } bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone, void (*func)(void* data), void* data); static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, void (*func)(void* data), void* data) { msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; msgpack_zone_finalizer* fin = fa->tail; if(fin == fa->end) { return msgpack_zone_push_finalizer_expand(zone, func, data); } fin->func = func; fin->data = data; ++fa->tail; return true; } static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b) { msgpack_zone tmp = *a; *a = *b; *b = tmp; } #ifdef __cplusplus } #endif #endif /* msgpack/zone.h */ msgpack-c-6.0.1/include/msgpack/vrefbuffer.h0000644000175000017460000000734314602664033017760 0ustar kondowheel/* * MessagePack for C zero-copy buffer implementation * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_VREFBUFFER_H #define MSGPACK_VREFBUFFER_H #include "zone.h" #include #include #if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__) #include typedef struct iovec msgpack_iovec; #else struct msgpack_iovec { void *iov_base; size_t iov_len; }; typedef struct msgpack_iovec msgpack_iovec; #endif #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_vrefbuffer Vectored Referencing buffer * @ingroup msgpack_buffer * @{ */ struct msgpack_vrefbuffer_chunk; typedef struct msgpack_vrefbuffer_chunk msgpack_vrefbuffer_chunk; typedef struct msgpack_vrefbuffer_inner_buffer { size_t free; char* ptr; msgpack_vrefbuffer_chunk* head; } msgpack_vrefbuffer_inner_buffer; typedef struct msgpack_vrefbuffer { msgpack_iovec* tail; msgpack_iovec* end; msgpack_iovec* array; size_t chunk_size; size_t ref_size; msgpack_vrefbuffer_inner_buffer inner_buffer; } msgpack_vrefbuffer; #ifndef MSGPACK_VREFBUFFER_REF_SIZE #define MSGPACK_VREFBUFFER_REF_SIZE 32 #endif #ifndef MSGPACK_VREFBUFFER_CHUNK_SIZE #define MSGPACK_VREFBUFFER_CHUNK_SIZE 8192 #endif MSGPACK_DLLEXPORT bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, size_t ref_size, size_t chunk_size); MSGPACK_DLLEXPORT void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf); static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size); static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf); static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len); static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref); MSGPACK_DLLEXPORT int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, const char* buf, size_t len); MSGPACK_DLLEXPORT int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, const char* buf, size_t len); MSGPACK_DLLEXPORT int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to); MSGPACK_DLLEXPORT void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref); /** @} */ static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size) { msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer)); if (vbuf == NULL) return NULL; if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) { free(vbuf); return NULL; } return vbuf; } static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf) { if(vbuf == NULL) { return; } msgpack_vrefbuffer_destroy(vbuf); free(vbuf); } static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len) { msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data; assert(buf || len == 0); if(!buf) return 0; if(len < vbuf->ref_size) { return msgpack_vrefbuffer_append_copy(vbuf, buf, len); } else { return msgpack_vrefbuffer_append_ref(vbuf, buf, len); } } static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref) { return vref->array; } static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref) { return (size_t)(vref->tail - vref->array); } #ifdef __cplusplus } #endif #endif /* msgpack/vrefbuffer.h */ msgpack-c-6.0.1/include/msgpack/pack.h0000644000175000017460000001332514602664033016537 0ustar kondowheel/* * MessagePack for C packing routine * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_PACK_H #define MSGPACK_PACK_H #include "pack_define.h" #include "object.h" #include "timestamp.h" #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_buffer Buffers * @ingroup msgpack * @{ * @} */ /** * @defgroup msgpack_pack Serializer * @ingroup msgpack * @{ */ typedef int (*msgpack_packer_write)(void* data, const char* buf, size_t len); typedef struct msgpack_packer { void* data; msgpack_packer_write callback; } msgpack_packer; static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); static void msgpack_packer_free(msgpack_packer* pk); static int msgpack_pack_char(msgpack_packer* pk, char d); static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d); static int msgpack_pack_short(msgpack_packer* pk, short d); static int msgpack_pack_int(msgpack_packer* pk, int d); static int msgpack_pack_long(msgpack_packer* pk, long d); static int msgpack_pack_long_long(msgpack_packer* pk, long long d); static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d); static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); static int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); static int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); static int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); static int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); static int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); static int msgpack_pack_int8(msgpack_packer* pk, int8_t d); static int msgpack_pack_int16(msgpack_packer* pk, int16_t d); static int msgpack_pack_int32(msgpack_packer* pk, int32_t d); static int msgpack_pack_int64(msgpack_packer* pk, int64_t d); static int msgpack_pack_fix_uint8(msgpack_packer* pk, uint8_t d); static int msgpack_pack_fix_uint16(msgpack_packer* pk, uint16_t d); static int msgpack_pack_fix_uint32(msgpack_packer* pk, uint32_t d); static int msgpack_pack_fix_uint64(msgpack_packer* pk, uint64_t d); static int msgpack_pack_fix_int8(msgpack_packer* pk, int8_t d); static int msgpack_pack_fix_int16(msgpack_packer* pk, int16_t d); static int msgpack_pack_fix_int32(msgpack_packer* pk, int32_t d); static int msgpack_pack_fix_int64(msgpack_packer* pk, int64_t d); static int msgpack_pack_float(msgpack_packer* pk, float d); static int msgpack_pack_double(msgpack_packer* pk, double d); static int msgpack_pack_nil(msgpack_packer* pk); static int msgpack_pack_true(msgpack_packer* pk); static int msgpack_pack_false(msgpack_packer* pk); static int msgpack_pack_array(msgpack_packer* pk, size_t n); static int msgpack_pack_map(msgpack_packer* pk, size_t n); static int msgpack_pack_str(msgpack_packer* pk, size_t l); static int msgpack_pack_str_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_str_with_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_v4raw(msgpack_packer* pk, size_t l); static int msgpack_pack_v4raw_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_bin(msgpack_packer* pk, size_t l); static int msgpack_pack_bin_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_bin_with_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_ext(msgpack_packer* pk, size_t l, int8_t type); static int msgpack_pack_ext_body(msgpack_packer* pk, const void* b, size_t l); static int msgpack_pack_ext_with_body(msgpack_packer* pk, const void* b, size_t l, int8_t type); static int msgpack_pack_timestamp(msgpack_packer* pk, const msgpack_timestamp* d); MSGPACK_DLLEXPORT int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); /** @} */ #define msgpack_pack_inline_func(name) \ inline int msgpack_pack ## name #define msgpack_pack_inline_func_cint(name) \ inline int msgpack_pack ## name #define msgpack_pack_inline_func_fixint(name) \ inline int msgpack_pack_fix ## name #define msgpack_pack_user msgpack_packer* #define msgpack_pack_append_buffer(user, buf, len) \ return (*(user)->callback)((user)->data, (const char*)buf, len) #include "pack_template.h" inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) { pk->data = data; pk->callback = callback; } inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) { msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); if(!pk) { return NULL; } msgpack_packer_init(pk, data, callback); return pk; } inline void msgpack_packer_free(msgpack_packer* pk) { free(pk); } inline int msgpack_pack_str_with_body(msgpack_packer* pk, const void* b, size_t l) { int ret = msgpack_pack_str(pk, l); if (ret != 0) { return ret; } return msgpack_pack_str_body(pk, b, l); } inline int msgpack_pack_bin_with_body(msgpack_packer* pk, const void* b, size_t l) { int ret = msgpack_pack_bin(pk, l); if (ret != 0) { return ret; } return msgpack_pack_bin_body(pk, b, l); } inline int msgpack_pack_ext_with_body(msgpack_packer* pk, const void* b, size_t l, int8_t type) { int ret = msgpack_pack_ext(pk, l, type); if (ret != 0) { return ret; } return msgpack_pack_ext_body(pk, b, l); } #ifdef __cplusplus } #endif #endif /* msgpack/pack.h */ msgpack-c-6.0.1/include/msgpack/sbuffer.h0000644000175000017460000000445714602664033017263 0ustar kondowheel/* * MessagePack for C simple buffer implementation * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_SBUFFER_H #define MSGPACK_SBUFFER_H #include #include #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_sbuffer Simple buffer * @ingroup msgpack_buffer * @{ */ typedef struct msgpack_sbuffer { size_t size; char* data; size_t alloc; } msgpack_sbuffer; static inline void msgpack_sbuffer_init(msgpack_sbuffer* sbuf) { memset(sbuf, 0, sizeof(msgpack_sbuffer)); } static inline void msgpack_sbuffer_destroy(msgpack_sbuffer* sbuf) { free(sbuf->data); } static inline msgpack_sbuffer* msgpack_sbuffer_new(void) { return (msgpack_sbuffer*)calloc(1, sizeof(msgpack_sbuffer)); } static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf) { if(sbuf == NULL) { return; } msgpack_sbuffer_destroy(sbuf); free(sbuf); } #ifndef MSGPACK_SBUFFER_INIT_SIZE #define MSGPACK_SBUFFER_INIT_SIZE 8192 #endif static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len) { msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data; assert(buf || len == 0); if(!buf) return 0; if(sbuf->alloc - sbuf->size < len) { void* tmp; size_t nsize = (sbuf->alloc) ? sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE; while(nsize < sbuf->size + len) { size_t tmp_nsize = nsize * 2; if (tmp_nsize <= nsize) { nsize = sbuf->size + len; break; } nsize = tmp_nsize; } tmp = realloc(sbuf->data, nsize); if(!tmp) { return -1; } sbuf->data = (char*)tmp; sbuf->alloc = nsize; } memcpy(sbuf->data + sbuf->size, buf, len); sbuf->size += len; return 0; } static inline char* msgpack_sbuffer_release(msgpack_sbuffer* sbuf) { char* tmp = sbuf->data; sbuf->size = 0; sbuf->data = NULL; sbuf->alloc = 0; return tmp; } static inline void msgpack_sbuffer_clear(msgpack_sbuffer* sbuf) { sbuf->size = 0; } /** @} */ #ifdef __cplusplus } #endif #endif /* msgpack/sbuffer.h */ msgpack-c-6.0.1/include/msgpack/object.h0000644000175000017460000000526514602664033017073 0ustar kondowheel/* * MessagePack for C dynamic typing routine * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_OBJECT_H #define MSGPACK_OBJECT_H #include "zone.h" #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_object Dynamically typed object * @ingroup msgpack * @{ */ typedef enum { MSGPACK_OBJECT_NIL = 0x00, MSGPACK_OBJECT_BOOLEAN = 0x01, MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02, MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03, MSGPACK_OBJECT_FLOAT32 = 0x0a, MSGPACK_OBJECT_FLOAT64 = 0x04, MSGPACK_OBJECT_FLOAT = 0x04, #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) MSGPACK_OBJECT_DOUBLE = MSGPACK_OBJECT_FLOAT, /* obsolete */ #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */ MSGPACK_OBJECT_STR = 0x05, MSGPACK_OBJECT_ARRAY = 0x06, MSGPACK_OBJECT_MAP = 0x07, MSGPACK_OBJECT_BIN = 0x08, MSGPACK_OBJECT_EXT = 0x09 } msgpack_object_type; struct msgpack_object; struct msgpack_object_kv; typedef struct { uint32_t size; struct msgpack_object* ptr; } msgpack_object_array; typedef struct { uint32_t size; struct msgpack_object_kv* ptr; } msgpack_object_map; typedef struct { uint32_t size; const char* ptr; } msgpack_object_str; typedef struct { uint32_t size; const char* ptr; } msgpack_object_bin; typedef struct { int8_t type; uint32_t size; const char* ptr; } msgpack_object_ext; typedef union { bool boolean; uint64_t u64; int64_t i64; #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) double dec; /* obsolete*/ #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */ double f64; msgpack_object_array array; msgpack_object_map map; msgpack_object_str str; msgpack_object_bin bin; msgpack_object_ext ext; } msgpack_object_union; typedef struct msgpack_object { msgpack_object_type type; msgpack_object_union via; } msgpack_object; typedef struct msgpack_object_kv { msgpack_object key; msgpack_object val; } msgpack_object_kv; #if !defined(_KERNEL_MODE) MSGPACK_DLLEXPORT void msgpack_object_print(FILE* out, msgpack_object o); #endif MSGPACK_DLLEXPORT int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object o); MSGPACK_DLLEXPORT bool msgpack_object_equal(const msgpack_object x, const msgpack_object y); /** @} */ #ifdef __cplusplus } #endif #endif /* msgpack/object.h */ msgpack-c-6.0.1/include/msgpack/gcc_atomic.h0000644000175000017460000000103114602664033017700 0ustar kondowheel/* * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_GCC_ATOMIC_H #define MSGPACK_GCC_ATOMIC_H #if defined(__cplusplus) extern "C" { #endif typedef int _msgpack_atomic_counter_t; int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); #if defined(__cplusplus) } #endif #endif // MSGPACK_GCC_ATOMIC_H msgpack-c-6.0.1/include/msgpack/pack_define.h0000644000175000017460000000066014602664033020047 0ustar kondowheel/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_PACK_DEFINE_H #define MSGPACK_PACK_DEFINE_H #include "msgpack/sysdep.h" #include #include #endif /* msgpack/pack_define.h */ msgpack-c-6.0.1/include/msgpack/unpack_template.h0000644000175000017460000004041014602664033020770 0ustar kondowheel/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef msgpack_unpack_func #error msgpack_unpack_func template is not defined #endif #ifndef msgpack_unpack_callback #error msgpack_unpack_callback template is not defined #endif #ifndef msgpack_unpack_struct #error msgpack_unpack_struct template is not defined #endif #ifndef msgpack_unpack_struct_decl #define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name) #endif #ifndef msgpack_unpack_object #error msgpack_unpack_object type is not defined #endif #ifndef msgpack_unpack_user #error msgpack_unpack_user type is not defined #endif #ifndef USE_CASE_RANGE #if !defined(_MSC_VER) #define USE_CASE_RANGE #endif #endif #if defined(_KERNEL_MODE) #undef assert #define assert NT_ASSERT #endif msgpack_unpack_struct_decl(_stack) { msgpack_unpack_object obj; size_t count; unsigned int ct; msgpack_unpack_object map_key; }; msgpack_unpack_struct_decl(_context) { msgpack_unpack_user user; unsigned int cs; unsigned int trail; unsigned int top; /* msgpack_unpack_struct(_stack)* stack; unsigned int stack_size; msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE]; */ msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE]; }; msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx) { ctx->cs = MSGPACK_CS_HEADER; ctx->trail = 0; ctx->top = 0; /* ctx->stack = ctx->embed_stack; ctx->stack_size = MSGPACK_EMBED_STACK_SIZE; */ ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user); } /* msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx) { if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) { free(ctx->stack); } } */ msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx) { return (ctx)->stack[0].obj; } msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off) { assert(len >= *off); { const unsigned char* p = (unsigned char*)data + *off; const unsigned char* const pe = (unsigned char*)data + len; const void* n = NULL; unsigned int trail = ctx->trail; unsigned int cs = ctx->cs; unsigned int top = ctx->top; msgpack_unpack_struct(_stack)* stack = ctx->stack; /* unsigned int stack_size = ctx->stack_size; */ msgpack_unpack_user* user = &ctx->user; msgpack_unpack_object obj; msgpack_unpack_struct(_stack)* c = NULL; int ret; #define push_simple_value(func) \ ret = msgpack_unpack_callback(func)(user, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define push_fixed_value(func, arg) \ ret = msgpack_unpack_callback(func)(user, arg, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define push_variable_value(func, base, pos, len) \ ret = msgpack_unpack_callback(func)(user, \ (const char*)base, (const char*)pos, len, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define again_fixed_trail(_cs, trail_len) \ trail = trail_len; \ cs = _cs; \ goto _fixed_trail_again #define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \ trail = trail_len; \ if(trail == 0) { goto ifzero; } \ cs = _cs; \ goto _fixed_trail_again #define start_container(func, count_, ct_) \ if(top >= MSGPACK_EMBED_STACK_SIZE) { \ ret = MSGPACK_UNPACK_NOMEM_ERROR; \ goto _failed; \ } /* FIXME */ \ ret = msgpack_unpack_callback(func)(user, count_, &stack[top].obj); \ if(ret < 0) { goto _failed; } \ if((count_) == 0) { obj = stack[top].obj; goto _push; } \ stack[top].ct = ct_; \ stack[top].count = count_; \ ++top; \ goto _header_again #define NEXT_CS(p) \ ((unsigned int)*p & 0x1f) #ifdef USE_CASE_RANGE #define SWITCH_RANGE_BEGIN switch(*p) { #define SWITCH_RANGE(FROM, TO) case FROM ... TO: #define SWITCH_RANGE_DEFAULT default: #define SWITCH_RANGE_END } #else #define SWITCH_RANGE_BEGIN { if(0) { #define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) { #define SWITCH_RANGE_DEFAULT } else { #define SWITCH_RANGE_END } } #endif if(p == pe) { goto _out; } do { switch(cs) { case MSGPACK_CS_HEADER: SWITCH_RANGE_BEGIN SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum push_fixed_value(_uint8, *(uint8_t*)p); SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum push_fixed_value(_int8, *(int8_t*)p); SWITCH_RANGE(0xc0, 0xdf) // Variable switch(*p) { case 0xc0: // nil push_simple_value(_nil); //case 0xc1: // string // again_terminal_trail(NEXT_CS(p), p+1); case 0xc2: // false push_simple_value(_false); case 0xc3: // true push_simple_value(_true); case 0xc4: // bin 8 case 0xc5: // bin 16 case 0xc6: // bin 32 again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); case 0xc7: // ext 8 case 0xc8: // ext 16 case 0xc9: // ext 32 again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) + 1) & 0x03)); case 0xca: // float case 0xcb: // double case 0xcc: // unsigned int 8 case 0xcd: // unsigned int 16 case 0xce: // unsigned int 32 case 0xcf: // unsigned int 64 case 0xd0: // signed int 8 case 0xd1: // signed int 16 case 0xd2: // signed int 32 case 0xd3: // signed int 64 again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); case 0xd4: // fixext 1 case 0xd5: // fixext 2 case 0xd6: // fixext 4 case 0xd7: // fixext 8 again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, (1 << (((unsigned int)*p) & 0x03)) + 1, _ext_zero); case 0xd8: // fixext 16 again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero); case 0xd9: // str 8 case 0xda: // str 16 case 0xdb: // str 32 again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) & 0x03) - 1)); case 0xdc: // array 16 case 0xdd: // array 32 case 0xde: // map 16 case 0xdf: // map 32 again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01)); default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } SWITCH_RANGE(0xa0, 0xbf) // FixStr again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, ((unsigned int)*p & 0x1f), _str_zero); SWITCH_RANGE(0x90, 0x9f) // FixArray start_container(_array, ((unsigned int)*p) & 0x0f, MSGPACK_CT_ARRAY_ITEM); SWITCH_RANGE(0x80, 0x8f) // FixMap start_container(_map, ((unsigned int)*p) & 0x0f, MSGPACK_CT_MAP_KEY); SWITCH_RANGE_DEFAULT ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; SWITCH_RANGE_END // end MSGPACK_CS_HEADER _fixed_trail_again: ++p; // fallthrough default: if((size_t)(pe - p) < trail) { goto _out; } n = p; p += trail - 1; switch(cs) { //case MSGPACK_CS_ //case MSGPACK_CS_ case MSGPACK_CS_FLOAT: { union { uint32_t i; float f; } mem; _msgpack_load32(uint32_t, n, &mem.i); push_fixed_value(_float, mem.f); } case MSGPACK_CS_DOUBLE: { union { uint64_t i; double f; } mem; _msgpack_load64(uint64_t, n, &mem.i); #if defined(TARGET_OS_IPHONE) // ok #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi // https://github.com/msgpack/msgpack-perl/pull/1 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL); #endif push_fixed_value(_double, mem.f); } case MSGPACK_CS_UINT_8: push_fixed_value(_uint8, *(uint8_t*)n); case MSGPACK_CS_UINT_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); push_fixed_value(_uint16, tmp); } case MSGPACK_CS_UINT_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); push_fixed_value(_uint32, tmp); } case MSGPACK_CS_UINT_64:{ uint64_t tmp; _msgpack_load64(uint64_t,n,&tmp); push_fixed_value(_uint64, tmp); } case MSGPACK_CS_INT_8: push_fixed_value(_int8, *(int8_t*)n); case MSGPACK_CS_INT_16:{ int16_t tmp; _msgpack_load16(int16_t,n,&tmp); push_fixed_value(_int16, tmp); } case MSGPACK_CS_INT_32:{ int32_t tmp; _msgpack_load32(int32_t,n,&tmp); push_fixed_value(_int32, tmp); } case MSGPACK_CS_INT_64:{ int64_t tmp; _msgpack_load64(int64_t,n,&tmp); push_fixed_value(_int64, tmp); } case MSGPACK_CS_FIXEXT_1: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 1+1, _ext_zero); case MSGPACK_CS_FIXEXT_2: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 2+1, _ext_zero); case MSGPACK_CS_FIXEXT_4: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 4+1, _ext_zero); case MSGPACK_CS_FIXEXT_8: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 8+1, _ext_zero); case MSGPACK_CS_FIXEXT_16: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero); case MSGPACK_CS_STR_8: again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, *(uint8_t*)n, _str_zero); case MSGPACK_CS_BIN_8: again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero); case MSGPACK_CS_EXT_8: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, (*(uint8_t*)n) + 1, _ext_zero); case MSGPACK_CS_STR_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero); } case MSGPACK_CS_BIN_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero); } case MSGPACK_CS_EXT_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero); } case MSGPACK_CS_STR_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero); } case MSGPACK_CS_BIN_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero); } case MSGPACK_CS_EXT_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero); } case MSGPACK_ACS_STR_VALUE: _str_zero: push_variable_value(_str, data, n, trail); case MSGPACK_ACS_BIN_VALUE: _bin_zero: push_variable_value(_bin, data, n, trail); case MSGPACK_ACS_EXT_VALUE: _ext_zero: push_variable_value(_ext, data, n, trail); case MSGPACK_CS_ARRAY_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM); } case MSGPACK_CS_ARRAY_32:{ /* FIXME security guard */ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM); } case MSGPACK_CS_MAP_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); start_container(_map, tmp, MSGPACK_CT_MAP_KEY); } case MSGPACK_CS_MAP_32:{ /* FIXME security guard */ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); start_container(_map, tmp, MSGPACK_CT_MAP_KEY); } default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } } _push: if(top == 0) { goto _finish; } c = &stack[top-1]; switch(c->ct) { case MSGPACK_CT_ARRAY_ITEM: ret = msgpack_unpack_callback(_array_item)(user, &c->obj, obj); \ if(ret < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } goto _header_again; case MSGPACK_CT_MAP_KEY: c->map_key = obj; c->ct = MSGPACK_CT_MAP_VALUE; goto _header_again; case MSGPACK_CT_MAP_VALUE: ret = msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj); \ if(ret < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } c->ct = MSGPACK_CT_MAP_KEY; goto _header_again; default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } _header_again: cs = MSGPACK_CS_HEADER; ++p; } while(p != pe); goto _out; _finish: stack[0].obj = obj; ++p; ret = 1; /*printf("-- finish --\n"); */ goto _end; _failed: /*printf("** FAILED **\n"); */ goto _end; _out: ret = 0; goto _end; _end: ctx->cs = cs; ctx->trail = trail; ctx->top = top; *off = (size_t)(p - (const unsigned char*)data); return ret; } } #undef msgpack_unpack_func #undef msgpack_unpack_callback #undef msgpack_unpack_struct #undef msgpack_unpack_object #undef msgpack_unpack_user #undef push_simple_value #undef push_fixed_value #undef push_variable_value #undef again_fixed_trail #undef again_fixed_trail_if_zero #undef start_container #undef NEXT_CS #undef SWITCH_RANGE_BEGIN #undef SWITCH_RANGE #undef SWITCH_RANGE_DEFAULT #undef SWITCH_RANGE_END msgpack-c-6.0.1/include/msgpack/zbuffer.h0000644000175000017460000001171214602664033017262 0ustar kondowheel/* * MessagePack for C deflate buffer implementation * * Copyright (C) 2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_ZBUFFER_H #define MSGPACK_ZBUFFER_H #include "sysdep.h" #include #include #include #include #ifdef __cplusplus extern "C" { #endif /** * @defgroup msgpack_zbuffer Compressed buffer * @ingroup msgpack_buffer * @{ */ typedef struct msgpack_zbuffer { z_stream stream; char* data; size_t init_size; } msgpack_zbuffer; #ifndef MSGPACK_ZBUFFER_INIT_SIZE #define MSGPACK_ZBUFFER_INIT_SIZE 8192 #endif static inline bool msgpack_zbuffer_init( msgpack_zbuffer* zbuf, int level, size_t init_size); static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf); static inline msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size); static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf); static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf); static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf); static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf); static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf); static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf); static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf); #ifndef MSGPACK_ZBUFFER_RESERVE_SIZE #define MSGPACK_ZBUFFER_RESERVE_SIZE 512 #endif static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len); static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf); static inline bool msgpack_zbuffer_init(msgpack_zbuffer* zbuf, int level, size_t init_size) { memset(zbuf, 0, sizeof(msgpack_zbuffer)); zbuf->init_size = init_size; if(deflateInit(&zbuf->stream, level) != Z_OK) { free(zbuf->data); return false; } return true; } static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf) { deflateEnd(&zbuf->stream); free(zbuf->data); } static inline msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size) { msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer)); if (zbuf == NULL) return NULL; if(!msgpack_zbuffer_init(zbuf, level, init_size)) { free(zbuf); return NULL; } return zbuf; } static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf) { if(zbuf == NULL) { return; } msgpack_zbuffer_destroy(zbuf); free(zbuf); } static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) { size_t used = (size_t)((char *)(zbuf->stream.next_out) - zbuf->data); size_t csize = used + zbuf->stream.avail_out; size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2; char* tmp = (char*)realloc(zbuf->data, nsize); if(tmp == NULL) { return false; } zbuf->data = tmp; zbuf->stream.next_out = (Bytef*)(tmp + used); zbuf->stream.avail_out = (uInt)(nsize - used); return true; } static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len) { msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; assert(buf || len == 0); if(!buf) return 0; zbuf->stream.next_in = (Bytef*)buf; zbuf->stream.avail_in = (uInt)len; while(zbuf->stream.avail_in > 0) { if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { if(!msgpack_zbuffer_expand(zbuf)) { return -1; } } if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) { return -1; } } return 0; } static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf) { while(true) { switch(deflate(&zbuf->stream, Z_FINISH)) { case Z_STREAM_END: return zbuf->data; case Z_OK: case Z_BUF_ERROR: if(!msgpack_zbuffer_expand(zbuf)) { return NULL; } break; default: return NULL; } } } static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf) { return zbuf->data; } static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf) { return (size_t)((char *)(zbuf->stream.next_out) - zbuf->data); } static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf) { zbuf->stream.avail_out += (uInt)((char*)zbuf->stream.next_out - zbuf->data); zbuf->stream.next_out = (Bytef*)zbuf->data; } static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf) { if(deflateReset(&zbuf->stream) != Z_OK) { return false; } msgpack_zbuffer_reset_buffer(zbuf); return true; } static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf) { char* tmp = zbuf->data; zbuf->data = NULL; zbuf->stream.next_out = NULL; zbuf->stream.avail_out = 0; return tmp; } /** @} */ #ifdef __cplusplus } #endif #endif /* msgpack/zbuffer.h */ msgpack-c-6.0.1/include/msgpack/version_master.h0000644000175000017460000000015114602712217020650 0ustar kondowheel#define MSGPACK_VERSION_MAJOR 6 #define MSGPACK_VERSION_MINOR 0 #define MSGPACK_VERSION_REVISION 1 msgpack-c-6.0.1/include/msgpack/version.h0000644000175000017460000000160414602664033017303 0ustar kondowheel/* * MessagePack for C version information * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_VERSION_H #define MSGPACK_VERSION_H #ifdef __cplusplus extern "C" { #endif MSGPACK_DLLEXPORT const char* msgpack_version(void); MSGPACK_DLLEXPORT int msgpack_version_major(void); MSGPACK_DLLEXPORT int msgpack_version_minor(void); MSGPACK_DLLEXPORT int msgpack_version_revision(void); #include "version_master.h" #define MSGPACK_STR(v) #v #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) #ifdef __cplusplus } #endif #endif /* msgpack/version.h */ msgpack-c-6.0.1/include/msgpack/util.h0000644000175000017460000000055214602664033016574 0ustar kondowheel/* * MessagePack for C utilities * * Copyright (C) 2014 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_UTIL_H #define MSGPACK_UTIL_H #define MSGPACK_UNUSED(a) (void)(a) #endif /* MSGPACK_UTIL_H */ msgpack-c-6.0.1/include/msgpack/unpack_define.h0000644000175000017460000000440114602664033020407 0ustar kondowheel/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_UNPACK_DEFINE_H #define MSGPACK_UNPACK_DEFINE_H #include "msgpack/sysdep.h" #include #include #include #include #ifdef __cplusplus extern "C" { #endif #ifndef MSGPACK_EMBED_STACK_SIZE #define MSGPACK_EMBED_STACK_SIZE 32 #endif typedef enum { MSGPACK_CS_HEADER = 0x00, // nil //MSGPACK_CS_ = 0x01, //MSGPACK_CS_ = 0x02, // false //MSGPACK_CS_ = 0x03, // true MSGPACK_CS_BIN_8 = 0x04, MSGPACK_CS_BIN_16 = 0x05, MSGPACK_CS_BIN_32 = 0x06, MSGPACK_CS_EXT_8 = 0x07, MSGPACK_CS_EXT_16 = 0x08, MSGPACK_CS_EXT_32 = 0x09, MSGPACK_CS_FLOAT = 0x0a, MSGPACK_CS_DOUBLE = 0x0b, MSGPACK_CS_UINT_8 = 0x0c, MSGPACK_CS_UINT_16 = 0x0d, MSGPACK_CS_UINT_32 = 0x0e, MSGPACK_CS_UINT_64 = 0x0f, MSGPACK_CS_INT_8 = 0x10, MSGPACK_CS_INT_16 = 0x11, MSGPACK_CS_INT_32 = 0x12, MSGPACK_CS_INT_64 = 0x13, MSGPACK_CS_FIXEXT_1 = 0x14, MSGPACK_CS_FIXEXT_2 = 0x15, MSGPACK_CS_FIXEXT_4 = 0x16, MSGPACK_CS_FIXEXT_8 = 0x17, MSGPACK_CS_FIXEXT_16 = 0x18, MSGPACK_CS_STR_8 = 0x19, // str8 MSGPACK_CS_STR_16 = 0x1a, // str16 MSGPACK_CS_STR_32 = 0x1b, // str32 MSGPACK_CS_ARRAY_16 = 0x1c, MSGPACK_CS_ARRAY_32 = 0x1d, MSGPACK_CS_MAP_16 = 0x1e, MSGPACK_CS_MAP_32 = 0x1f, //MSGPACK_ACS_BIG_INT_VALUE, //MSGPACK_ACS_BIG_FLOAT_VALUE, MSGPACK_ACS_STR_VALUE, MSGPACK_ACS_BIN_VALUE, MSGPACK_ACS_EXT_VALUE } msgpack_unpack_state; typedef enum { MSGPACK_CT_ARRAY_ITEM, MSGPACK_CT_MAP_KEY, MSGPACK_CT_MAP_VALUE } msgpack_container_type; #ifdef __cplusplus } #endif #endif /* msgpack/unpack_define.h */ msgpack-c-6.0.1/include/msgpack/timestamp.h0000644000175000017460000000256714602664033017632 0ustar kondowheel/* * MessagePack for C TimeStamp * * Copyright (C) 2018 KONDO Takatoshi * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_TIMESTAMP_H #define MSGPACK_TIMESTAMP_H #include #ifdef __cplusplus extern "C" { #endif typedef struct msgpack_timestamp { int64_t tv_sec; uint32_t tv_nsec; } msgpack_timestamp; static inline bool msgpack_object_to_timestamp(const msgpack_object* obj, msgpack_timestamp* ts) { if (obj->type != MSGPACK_OBJECT_EXT) return false; if (obj->via.ext.type != -1) return false; switch (obj->via.ext.size) { case 4: ts->tv_nsec = 0; { uint32_t v; _msgpack_load32(uint32_t, obj->via.ext.ptr, &v); ts->tv_sec = v; } return true; case 8: { uint64_t value; _msgpack_load64(uint64_t, obj->via.ext.ptr, &value); ts->tv_nsec = (uint32_t)(value >> 34); ts->tv_sec = value & 0x00000003ffffffffLL; return true; } case 12: _msgpack_load32(uint32_t, obj->via.ext.ptr, &ts->tv_nsec); _msgpack_load64(int64_t, obj->via.ext.ptr + 4, &ts->tv_sec); return true; default: return false; } } #ifdef __cplusplus } #endif #endif /* msgpack/timestamp.h */ msgpack-c-6.0.1/src/0000755000175000017460000000000014602664033013163 5ustar kondowheelmsgpack-c-6.0.1/src/version.c0000644000175000017460000000046414602664033015020 0ustar kondowheel#include "msgpack.h" const char* msgpack_version(void) { return MSGPACK_VERSION; } int msgpack_version_major(void) { return MSGPACK_VERSION_MAJOR; } int msgpack_version_minor(void) { return MSGPACK_VERSION_MINOR; } int msgpack_version_revision(void) { return MSGPACK_VERSION_REVISION; } msgpack-c-6.0.1/src/unpack.c0000644000175000017460000004267514602664033014626 0ustar kondowheel/* * MessagePack for C unpacking routine * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #include "msgpack/unpack.h" #include "msgpack/unpack_define.h" #include "msgpack/util.h" #include #ifdef _msgpack_atomic_counter_header #include _msgpack_atomic_counter_header #endif typedef struct { msgpack_zone** z; bool referenced; } unpack_user; #define msgpack_unpack_struct(name) \ struct template ## name #define msgpack_unpack_func(ret, name) \ ret template ## name #define msgpack_unpack_callback(name) \ template_callback ## name #define msgpack_unpack_object msgpack_object #define msgpack_unpack_user unpack_user struct template_context; typedef struct template_context template_context; static void template_init(template_context* ctx); static msgpack_object template_data(template_context* ctx); static int template_execute( template_context* ctx, const char* data, size_t len, size_t* off); static inline msgpack_object template_callback_root(unpack_user* u) { msgpack_object o; MSGPACK_UNUSED(u); o.type = MSGPACK_OBJECT_NIL; return o; } static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; } static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; } static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; } static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; } static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_object* o) { MSGPACK_UNUSED(u); if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; } else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } } static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_object* o) { MSGPACK_UNUSED(u); if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; } else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } } static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_object* o) { MSGPACK_UNUSED(u); if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; } else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } } static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_object* o) { MSGPACK_UNUSED(u); if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; } else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } } static inline int template_callback_float(unpack_user* u, float d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_FLOAT32; o->via.f64 = d; return 0; } static inline int template_callback_double(unpack_user* u, double d, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_FLOAT64; o->via.f64 = d; return 0; } static inline int template_callback_nil(unpack_user* u, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_NIL; return 0; } static inline int template_callback_true(unpack_user* u, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_BOOLEAN; o->via.boolean = true; return 0; } static inline int template_callback_false(unpack_user* u, msgpack_object* o) { MSGPACK_UNUSED(u); o->type = MSGPACK_OBJECT_BOOLEAN; o->via.boolean = false; return 0; } static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o) { size_t size; // Let's leverage the fact that sizeof(msgpack_object) is a compile time constant // to check for int overflows. // Note - while n is constrained to 32-bit, the product of n * sizeof(msgpack_object) // might not be constrained to 4GB on 64-bit systems #if SIZE_MAX == UINT_MAX if (n > SIZE_MAX/sizeof(msgpack_object)) return MSGPACK_UNPACK_NOMEM_ERROR; #endif o->type = MSGPACK_OBJECT_ARRAY; o->via.array.size = 0; size = n * sizeof(msgpack_object); if (*u->z == NULL) { *u->z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); if(*u->z == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } } // Unsure whether size = 0 should be an error, and if so, what to return o->via.array.ptr = (msgpack_object*)msgpack_zone_malloc(*u->z, size); if(o->via.array.ptr == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } return 0; } static inline int template_callback_array_item(unpack_user* u, msgpack_object* c, msgpack_object o) { MSGPACK_UNUSED(u); #if defined(__GNUC__) && !defined(__clang__) memcpy(&c->via.array.ptr[c->via.array.size], &o, sizeof(msgpack_object)); #else /* __GNUC__ && !__clang__ */ c->via.array.ptr[c->via.array.size] = o; #endif /* __GNUC__ && !__clang__ */ ++c->via.array.size; return 0; } static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_object* o) { size_t size; // Let's leverage the fact that sizeof(msgpack_object_kv) is a compile time constant // to check for int overflows // Note - while n is constrained to 32-bit, the product of n * sizeof(msgpack_object) // might not be constrained to 4GB on 64-bit systems // Note - this will always be false on 64-bit systems #if SIZE_MAX == UINT_MAX if (n > SIZE_MAX/sizeof(msgpack_object_kv)) return MSGPACK_UNPACK_NOMEM_ERROR; #endif o->type = MSGPACK_OBJECT_MAP; o->via.map.size = 0; size = n * sizeof(msgpack_object_kv); if (*u->z == NULL) { *u->z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); if(*u->z == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } } // Should size = 0 be an error? If so, what error to return? o->via.map.ptr = (msgpack_object_kv*)msgpack_zone_malloc(*u->z, size); if(o->via.map.ptr == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } return 0; } static inline int template_callback_map_item(unpack_user* u, msgpack_object* c, msgpack_object k, msgpack_object v) { MSGPACK_UNUSED(u); #if defined(__GNUC__) && !defined(__clang__) memcpy(&c->via.map.ptr[c->via.map.size].key, &k, sizeof(msgpack_object)); memcpy(&c->via.map.ptr[c->via.map.size].val, &v, sizeof(msgpack_object)); #else /* __GNUC__ && !__clang__ */ c->via.map.ptr[c->via.map.size].key = k; c->via.map.ptr[c->via.map.size].val = v; #endif /* __GNUC__ && !__clang__ */ ++c->via.map.size; return 0; } static inline int template_callback_str(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o) { MSGPACK_UNUSED(b); if (*u->z == NULL) { *u->z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); if(*u->z == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } } o->type = MSGPACK_OBJECT_STR; o->via.str.ptr = p; o->via.str.size = l; u->referenced = true; return 0; } static inline int template_callback_bin(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o) { MSGPACK_UNUSED(b); if (*u->z == NULL) { *u->z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); if(*u->z == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } } o->type = MSGPACK_OBJECT_BIN; o->via.bin.ptr = p; o->via.bin.size = l; u->referenced = true; return 0; } static inline int template_callback_ext(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o) { MSGPACK_UNUSED(b); if (l == 0) { return MSGPACK_UNPACK_PARSE_ERROR; } if (*u->z == NULL) { *u->z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); if(*u->z == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; } } o->type = MSGPACK_OBJECT_EXT; o->via.ext.type = *p; o->via.ext.ptr = p + 1; o->via.ext.size = l - 1; u->referenced = true; return 0; } #include "msgpack/unpack_template.h" #define CTX_CAST(m) ((template_context*)(m)) #define CTX_REFERENCED(mpac) CTX_CAST((mpac)->ctx)->user.referenced #define COUNTER_SIZE (sizeof(_msgpack_atomic_counter_t)) static inline void init_count(void* buffer) { *(volatile _msgpack_atomic_counter_t*)buffer = 1; } static inline void decr_count(void* buffer) { // atomic if(--*(_msgpack_atomic_counter_t*)buffer == 0) { free(buffer); } if(_msgpack_sync_decr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer) == 0) { free(buffer); } } static inline void incr_count(void* buffer) { // atomic ++*(_msgpack_atomic_counter_t*)buffer; _msgpack_sync_incr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer); } static inline _msgpack_atomic_counter_t get_count(void* buffer) { return *(volatile _msgpack_atomic_counter_t*)buffer; } bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size) { char* buffer; void* ctx; if(initial_buffer_size < COUNTER_SIZE) { initial_buffer_size = COUNTER_SIZE; } buffer = (char*)malloc(initial_buffer_size); if(buffer == NULL) { return false; } ctx = malloc(sizeof(template_context)); if(ctx == NULL) { free(buffer); return false; } mpac->buffer = buffer; mpac->used = COUNTER_SIZE; mpac->free = initial_buffer_size - mpac->used; mpac->off = COUNTER_SIZE; mpac->parsed = 0; mpac->initial_buffer_size = initial_buffer_size; mpac->z = NULL; mpac->ctx = ctx; init_count(mpac->buffer); template_init(CTX_CAST(mpac->ctx)); CTX_CAST(mpac->ctx)->user.z = &mpac->z; CTX_CAST(mpac->ctx)->user.referenced = false; return true; } void msgpack_unpacker_destroy(msgpack_unpacker* mpac) { msgpack_zone_free(mpac->z); free(mpac->ctx); decr_count(mpac->buffer); } msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size) { msgpack_unpacker* mpac = (msgpack_unpacker*)malloc(sizeof(msgpack_unpacker)); if(mpac == NULL) { return NULL; } if(!msgpack_unpacker_init(mpac, initial_buffer_size)) { free(mpac); return NULL; } return mpac; } void msgpack_unpacker_free(msgpack_unpacker* mpac) { msgpack_unpacker_destroy(mpac); free(mpac); } bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size) { if(mpac->used == mpac->off && get_count(mpac->buffer) == 1 && !CTX_REFERENCED(mpac)) { // rewind buffer mpac->free += mpac->used - COUNTER_SIZE; mpac->used = COUNTER_SIZE; mpac->off = COUNTER_SIZE; if(mpac->free >= size) { return true; } } if(mpac->off == COUNTER_SIZE) { char* tmp; size_t next_size = (mpac->used + mpac->free) * 2; // include COUNTER_SIZE while(next_size < size + mpac->used) { size_t tmp_next_size = next_size * 2; if (tmp_next_size <= next_size) { next_size = size + mpac->used; break; } next_size = tmp_next_size; } tmp = (char*)realloc(mpac->buffer, next_size); if(tmp == NULL) { return false; } mpac->buffer = tmp; mpac->free = next_size - mpac->used; } else { char* tmp; size_t next_size = mpac->initial_buffer_size; // include COUNTER_SIZE size_t not_parsed = mpac->used - mpac->off; while(next_size < size + not_parsed + COUNTER_SIZE) { size_t tmp_next_size = next_size * 2; if (tmp_next_size <= next_size) { next_size = size + not_parsed + COUNTER_SIZE; break; } next_size = tmp_next_size; } tmp = (char*)malloc(next_size); if(tmp == NULL) { return false; } init_count(tmp); memcpy(tmp+COUNTER_SIZE, mpac->buffer+mpac->off, not_parsed); if(CTX_REFERENCED(mpac)) { if(!msgpack_zone_push_finalizer(mpac->z, decr_count, mpac->buffer)) { free(tmp); return false; } CTX_REFERENCED(mpac) = false; } else { decr_count(mpac->buffer); } mpac->buffer = tmp; mpac->used = not_parsed + COUNTER_SIZE; mpac->free = next_size - mpac->used; mpac->off = COUNTER_SIZE; } return true; } int msgpack_unpacker_execute(msgpack_unpacker* mpac) { size_t off = mpac->off; int ret = template_execute(CTX_CAST(mpac->ctx), mpac->buffer, mpac->used, &mpac->off); if(mpac->off > off) { mpac->parsed += mpac->off - off; } return ret; } msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac) { return template_data(CTX_CAST(mpac->ctx)); } msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac) { msgpack_zone* old = mpac->z; if (old == NULL) return NULL; if(!msgpack_unpacker_flush_zone(mpac)) { return NULL; } mpac->z = NULL; CTX_CAST(mpac->ctx)->user.z = &mpac->z; return old; } void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac) { msgpack_zone_clear(mpac->z); } bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac) { if(CTX_REFERENCED(mpac)) { if(!msgpack_zone_push_finalizer(mpac->z, decr_count, mpac->buffer)) { return false; } CTX_REFERENCED(mpac) = false; incr_count(mpac->buffer); } return true; } void msgpack_unpacker_reset(msgpack_unpacker* mpac) { template_init(CTX_CAST(mpac->ctx)); // don't reset referenced flag mpac->parsed = 0; } static inline msgpack_unpack_return unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result) { int ret; msgpack_unpacked_destroy(result); ret = msgpack_unpacker_execute(mpac); if(ret < 0) { result->zone = NULL; memset(&result->data, 0, sizeof(msgpack_object)); return (msgpack_unpack_return)ret; } if(ret == 0) { return MSGPACK_UNPACK_CONTINUE; } result->zone = msgpack_unpacker_release_zone(mpac); result->data = msgpack_unpacker_data(mpac); return MSGPACK_UNPACK_SUCCESS; } msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result) { msgpack_unpack_return ret; ret = unpacker_next(mpac, result); if (ret == MSGPACK_UNPACK_SUCCESS) { msgpack_unpacker_reset(mpac); } return ret; } msgpack_unpack_return msgpack_unpacker_next_with_size(msgpack_unpacker* mpac, msgpack_unpacked* result, size_t *p_bytes) { msgpack_unpack_return ret; ret = unpacker_next(mpac, result); if (ret == MSGPACK_UNPACK_SUCCESS || ret == MSGPACK_UNPACK_CONTINUE) { *p_bytes = mpac->parsed; } if (ret == MSGPACK_UNPACK_SUCCESS) { msgpack_unpacker_reset(mpac); } return ret; } msgpack_unpack_return msgpack_unpack(const char* data, size_t len, size_t* off, msgpack_zone* result_zone, msgpack_object* result) { size_t noff = 0; if(off != NULL) { noff = *off; } if(len <= noff) { // FIXME return MSGPACK_UNPACK_CONTINUE; } else { int e; template_context ctx; template_init(&ctx); ctx.user.z = &result_zone; ctx.user.referenced = false; e = template_execute(&ctx, data, len, &noff); if(e < 0) { return (msgpack_unpack_return)e; } if(off != NULL) { *off = noff; } if(e == 0) { return MSGPACK_UNPACK_CONTINUE; } *result = template_data(&ctx); if(noff < len) { return MSGPACK_UNPACK_EXTRA_BYTES; } return MSGPACK_UNPACK_SUCCESS; } } msgpack_unpack_return msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off) { size_t noff = 0; msgpack_unpacked_destroy(result); if(off != NULL) { noff = *off; } if(len <= noff) { return MSGPACK_UNPACK_CONTINUE; } { int e; template_context ctx; template_init(&ctx); ctx.user.z = &result->zone; ctx.user.referenced = false; e = template_execute(&ctx, data, len, &noff); if(off != NULL) { *off = noff; } if(e < 0) { msgpack_zone_free(result->zone); result->zone = NULL; return (msgpack_unpack_return)e; } if(e == 0) { return MSGPACK_UNPACK_CONTINUE; } result->data = template_data(&ctx); return MSGPACK_UNPACK_SUCCESS; } } #if defined(MSGPACK_OLD_COMPILER_BUS_ERROR_WORKAROUND) // FIXME: Dirty hack to avoid a bus error caused by OS X's old gcc. static void dummy_function_to_avoid_bus_error() { } #endif msgpack-c-6.0.1/src/zone.c0000644000175000017460000001173314602664033014307 0ustar kondowheel/* * MessagePack for C memory pool implementation * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #include "msgpack/zone.h" #include #include struct msgpack_zone_chunk { struct msgpack_zone_chunk* next; /* data ... */ }; static inline bool init_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size) { msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc( sizeof(msgpack_zone_chunk) + chunk_size); if(chunk == NULL) { return false; } cl->head = chunk; cl->free = chunk_size; cl->ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk); chunk->next = NULL; return true; } static inline void destroy_chunk_list(msgpack_zone_chunk_list* cl) { msgpack_zone_chunk* c = cl->head; while(true) { msgpack_zone_chunk* n = c->next; free(c); if(n != NULL) { c = n; } else { break; } } } static inline void clear_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size) { msgpack_zone_chunk* c = cl->head; while(true) { msgpack_zone_chunk* n = c->next; if(n != NULL) { free(c); c = n; } else { cl->head = c; break; } } cl->head->next = NULL; cl->free = chunk_size; cl->ptr = ((char*)cl->head) + sizeof(msgpack_zone_chunk); } void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size) { msgpack_zone_chunk_list* const cl = &zone->chunk_list; msgpack_zone_chunk* chunk; size_t sz = zone->chunk_size; while(sz < size) { size_t tmp_sz = sz * 2; if (tmp_sz <= sz) { sz = size; break; } sz = tmp_sz; } chunk = (msgpack_zone_chunk*)malloc( sizeof(msgpack_zone_chunk) + sz); if (chunk == NULL) { return NULL; } else { char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk); chunk->next = cl->head; cl->head = chunk; cl->free = sz - size; cl->ptr = ptr + size; return ptr; } } static inline void init_finalizer_array(msgpack_zone_finalizer_array* fa) { fa->tail = NULL; fa->end = NULL; fa->array = NULL; } static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa) { msgpack_zone_finalizer* fin = fa->tail; for(; fin != fa->array; --fin) { (*(fin-1)->func)((fin-1)->data); } } static inline void destroy_finalizer_array(msgpack_zone_finalizer_array* fa) { call_finalizer_array(fa); free(fa->array); } static inline void clear_finalizer_array(msgpack_zone_finalizer_array* fa) { call_finalizer_array(fa); fa->tail = fa->array; } bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone, void (*func)(void* data), void* data) { msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; msgpack_zone_finalizer* tmp; const size_t nused = (size_t)(fa->end - fa->array); size_t nnext; if(nused == 0) { nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ? 72 / sizeof(msgpack_zone_finalizer) : 8; } else { nnext = nused * 2; } tmp = (msgpack_zone_finalizer*)realloc(fa->array, sizeof(msgpack_zone_finalizer) * nnext); if(tmp == NULL) { return false; } fa->array = tmp; fa->end = tmp + nnext; fa->tail = tmp + nused; fa->tail->func = func; fa->tail->data = data; ++fa->tail; return true; } bool msgpack_zone_is_empty(msgpack_zone* zone) { msgpack_zone_chunk_list* const cl = &zone->chunk_list; msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; return cl->free == zone->chunk_size && cl->head->next == NULL && fa->tail == fa->array; } void msgpack_zone_destroy(msgpack_zone* zone) { destroy_finalizer_array(&zone->finalizer_array); destroy_chunk_list(&zone->chunk_list); } void msgpack_zone_clear(msgpack_zone* zone) { clear_finalizer_array(&zone->finalizer_array); clear_chunk_list(&zone->chunk_list, zone->chunk_size); } bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size) { zone->chunk_size = chunk_size; if(!init_chunk_list(&zone->chunk_list, chunk_size)) { return false; } init_finalizer_array(&zone->finalizer_array); return true; } msgpack_zone* msgpack_zone_new(size_t chunk_size) { msgpack_zone* zone = (msgpack_zone*)malloc( sizeof(msgpack_zone)); if(zone == NULL) { return NULL; } zone->chunk_size = chunk_size; if(!init_chunk_list(&zone->chunk_list, chunk_size)) { free(zone); return NULL; } init_finalizer_array(&zone->finalizer_array); return zone; } void msgpack_zone_free(msgpack_zone* zone) { if(zone == NULL) { return; } msgpack_zone_destroy(zone); free(zone); } msgpack-c-6.0.1/src/vrefbuffer.c0000644000175000017460000001471214602664033015470 0ustar kondowheel/* * MessagePack for C zero-copy buffer implementation * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #include "msgpack/vrefbuffer.h" #include #include #define MSGPACK_PACKER_MAX_BUFFER_SIZE 9 struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk* next; /* data ... */ }; bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, size_t ref_size, size_t chunk_size) { size_t nfirst; msgpack_iovec* array; msgpack_vrefbuffer_chunk* chunk; if (ref_size == 0) { ref_size = MSGPACK_VREFBUFFER_REF_SIZE; } if(chunk_size == 0) { chunk_size = MSGPACK_VREFBUFFER_CHUNK_SIZE; } vbuf->chunk_size = chunk_size; vbuf->ref_size = ref_size > MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ? ref_size : MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ; if((sizeof(msgpack_vrefbuffer_chunk) + chunk_size) < chunk_size) { return false; } nfirst = (sizeof(msgpack_iovec) < 72/2) ? 72 / sizeof(msgpack_iovec) : 8; array = (msgpack_iovec*)malloc( sizeof(msgpack_iovec) * nfirst); if(array == NULL) { return false; } vbuf->tail = array; vbuf->end = array + nfirst; vbuf->array = array; chunk = (msgpack_vrefbuffer_chunk*)malloc( sizeof(msgpack_vrefbuffer_chunk) + chunk_size); if(chunk == NULL) { free(array); return false; } else { msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; ib->free = chunk_size; ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); ib->head = chunk; chunk->next = NULL; return true; } } void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf) { msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head; while(true) { msgpack_vrefbuffer_chunk* n = c->next; free(c); if(n != NULL) { c = n; } else { break; } } free(vbuf->array); } void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf) { msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head->next; msgpack_vrefbuffer_chunk* n; while(c != NULL) { n = c->next; free(c); c = n; } { msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; msgpack_vrefbuffer_chunk* chunk = ib->head; chunk->next = NULL; ib->free = vbuf->chunk_size; ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); vbuf->tail = vbuf->array; } } int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, const char* buf, size_t len) { if(vbuf->tail == vbuf->end) { const size_t nused = (size_t)(vbuf->tail - vbuf->array); const size_t nnext = nused * 2; msgpack_iovec* nvec = (msgpack_iovec*)realloc( vbuf->array, sizeof(msgpack_iovec)*nnext); if(nvec == NULL) { return -1; } vbuf->array = nvec; vbuf->end = nvec + nnext; vbuf->tail = nvec + nused; } vbuf->tail->iov_base = (char*)buf; vbuf->tail->iov_len = len; ++vbuf->tail; return 0; } int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, const char* buf, size_t len) { msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; char* m; if(ib->free < len) { msgpack_vrefbuffer_chunk* chunk; size_t sz = vbuf->chunk_size; if(sz < len) { sz = len; } if((sizeof(msgpack_vrefbuffer_chunk) + sz) < sz){ return -1; } chunk = (msgpack_vrefbuffer_chunk*)malloc( sizeof(msgpack_vrefbuffer_chunk) + sz); if(chunk == NULL) { return -1; } chunk->next = ib->head; ib->head = chunk; ib->free = sz; ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); } m = ib->ptr; memcpy(m, buf, len); ib->free -= len; ib->ptr += len; if(vbuf->tail != vbuf->array && m == (const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) { (vbuf->tail-1)->iov_len += len; return 0; } else { return msgpack_vrefbuffer_append_ref(vbuf, m, len); } } int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) { size_t sz = vbuf->chunk_size; msgpack_vrefbuffer_chunk* empty; if((sizeof(msgpack_vrefbuffer_chunk) + sz) < sz){ return -1; } empty = (msgpack_vrefbuffer_chunk*)malloc( sizeof(msgpack_vrefbuffer_chunk) + sz); if(empty == NULL) { return -1; } empty->next = NULL; { const size_t nused = (size_t)(vbuf->tail - vbuf->array); if(to->tail + nused < vbuf->end) { msgpack_iovec* nvec; const size_t tosize = (size_t)(to->tail - to->array); const size_t reqsize = nused + tosize; size_t nnext = (size_t)(to->end - to->array) * 2; while(nnext < reqsize) { size_t tmp_nnext = nnext * 2; if (tmp_nnext <= nnext) { nnext = reqsize; break; } nnext = tmp_nnext; } nvec = (msgpack_iovec*)realloc( to->array, sizeof(msgpack_iovec)*nnext); if(nvec == NULL) { free(empty); return -1; } to->array = nvec; to->end = nvec + nnext; to->tail = nvec + tosize; } memcpy(to->tail, vbuf->array, sizeof(msgpack_iovec)*nused); to->tail += nused; vbuf->tail = vbuf->array; { msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; msgpack_vrefbuffer_inner_buffer* const toib = &to->inner_buffer; msgpack_vrefbuffer_chunk* last = ib->head; while(last->next != NULL) { last = last->next; } last->next = toib->head; toib->head = ib->head; if(toib->free < ib->free) { toib->free = ib->free; toib->ptr = ib->ptr; } ib->head = empty; ib->free = sz; ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk); } } return 0; } msgpack-c-6.0.1/src/objectc.c0000644000175000017460000003677514602664033014762 0ustar kondowheel/* * MessagePack for C dynamic typing routine * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #if defined(_KERNEL_MODE) # undef _NO_CRT_STDIO_INLINE # define _NO_CRT_STDIO_INLINE #endif #include "msgpack/object.h" #include "msgpack/pack.h" #include #include #include #if defined(_MSC_VER) #if _MSC_VER >= 1800 #include #else #define PRIu64 "I64u" #define PRIi64 "I64i" #define PRIi8 "i" #endif #else #include #endif #if defined(_KERNEL_MODE) # undef snprintf # define snprintf _snprintf #endif int msgpack_pack_object(msgpack_packer* pk, msgpack_object d) { switch(d.type) { case MSGPACK_OBJECT_NIL: return msgpack_pack_nil(pk); case MSGPACK_OBJECT_BOOLEAN: if(d.via.boolean) { return msgpack_pack_true(pk); } else { return msgpack_pack_false(pk); } case MSGPACK_OBJECT_POSITIVE_INTEGER: return msgpack_pack_uint64(pk, d.via.u64); case MSGPACK_OBJECT_NEGATIVE_INTEGER: return msgpack_pack_int64(pk, d.via.i64); case MSGPACK_OBJECT_FLOAT32: return msgpack_pack_float(pk, (float)d.via.f64); case MSGPACK_OBJECT_FLOAT64: return msgpack_pack_double(pk, d.via.f64); case MSGPACK_OBJECT_STR: { int ret = msgpack_pack_str(pk, d.via.str.size); if(ret < 0) { return ret; } return msgpack_pack_str_body(pk, d.via.str.ptr, d.via.str.size); } case MSGPACK_OBJECT_BIN: { int ret = msgpack_pack_bin(pk, d.via.bin.size); if(ret < 0) { return ret; } return msgpack_pack_bin_body(pk, d.via.bin.ptr, d.via.bin.size); } case MSGPACK_OBJECT_EXT: { int ret = msgpack_pack_ext(pk, d.via.ext.size, d.via.ext.type); if(ret < 0) { return ret; } return msgpack_pack_ext_body(pk, d.via.ext.ptr, d.via.ext.size); } case MSGPACK_OBJECT_ARRAY: { int ret = msgpack_pack_array(pk, d.via.array.size); if(ret < 0) { return ret; } else { msgpack_object* o = d.via.array.ptr; msgpack_object* const oend = d.via.array.ptr + d.via.array.size; for(; o != oend; ++o) { ret = msgpack_pack_object(pk, *o); if(ret < 0) { return ret; } } return 0; } } case MSGPACK_OBJECT_MAP: { int ret = msgpack_pack_map(pk, d.via.map.size); if(ret < 0) { return ret; } else { msgpack_object_kv* kv = d.via.map.ptr; msgpack_object_kv* const kvend = d.via.map.ptr + d.via.map.size; for(; kv != kvend; ++kv) { ret = msgpack_pack_object(pk, kv->key); if(ret < 0) { return ret; } ret = msgpack_pack_object(pk, kv->val); if(ret < 0) { return ret; } } return 0; } } default: return -1; } } #if !defined(_KERNEL_MODE) static void msgpack_object_bin_print(FILE* out, const char *ptr, size_t size) { size_t i; for (i = 0; i < size; ++i) { if (ptr[i] == '"') { fputs("\\\"", out); } else if (isprint((unsigned char)ptr[i])) { fputc(ptr[i], out); } else { fprintf(out, "\\x%02x", (unsigned char)ptr[i]); } } } void msgpack_object_print(FILE* out, msgpack_object o) { switch(o.type) { case MSGPACK_OBJECT_NIL: fprintf(out, "nil"); break; case MSGPACK_OBJECT_BOOLEAN: fprintf(out, (o.via.boolean ? "true" : "false")); break; case MSGPACK_OBJECT_POSITIVE_INTEGER: #if defined(PRIu64) fprintf(out, "%" PRIu64, o.via.u64); #else if (o.via.u64 > ULONG_MAX) fprintf(out, "over 4294967295"); else fprintf(out, "%lu", (unsigned long)o.via.u64); #endif break; case MSGPACK_OBJECT_NEGATIVE_INTEGER: #if defined(PRIi64) fprintf(out, "%" PRIi64, o.via.i64); #else if (o.via.i64 > LONG_MAX) fprintf(out, "over +2147483647"); else if (o.via.i64 < LONG_MIN) fprintf(out, "under -2147483648"); else fprintf(out, "%ld", (signed long)o.via.i64); #endif break; case MSGPACK_OBJECT_FLOAT32: case MSGPACK_OBJECT_FLOAT64: fprintf(out, "%f", o.via.f64); break; case MSGPACK_OBJECT_STR: fprintf(out, "\""); fwrite(o.via.str.ptr, o.via.str.size, 1, out); fprintf(out, "\""); break; case MSGPACK_OBJECT_BIN: fprintf(out, "\""); msgpack_object_bin_print(out, o.via.bin.ptr, o.via.bin.size); fprintf(out, "\""); break; case MSGPACK_OBJECT_EXT: #if defined(PRIi8) fprintf(out, "(ext: %" PRIi8 ")", o.via.ext.type); #else fprintf(out, "(ext: %d)", (int)o.via.ext.type); #endif fprintf(out, "\""); msgpack_object_bin_print(out, o.via.ext.ptr, o.via.ext.size); fprintf(out, "\""); break; case MSGPACK_OBJECT_ARRAY: fprintf(out, "["); if(o.via.array.size != 0) { msgpack_object* p = o.via.array.ptr; msgpack_object* const pend = o.via.array.ptr + o.via.array.size; msgpack_object_print(out, *p); ++p; for(; p < pend; ++p) { fprintf(out, ", "); msgpack_object_print(out, *p); } } fprintf(out, "]"); break; case MSGPACK_OBJECT_MAP: fprintf(out, "{"); if(o.via.map.size != 0) { msgpack_object_kv* p = o.via.map.ptr; msgpack_object_kv* const pend = o.via.map.ptr + o.via.map.size; msgpack_object_print(out, p->key); fprintf(out, "=>"); msgpack_object_print(out, p->val); ++p; for(; p < pend; ++p) { fprintf(out, ", "); msgpack_object_print(out, p->key); fprintf(out, "=>"); msgpack_object_print(out, p->val); } } fprintf(out, "}"); break; default: // FIXME #if defined(PRIu64) fprintf(out, "#", o.type, o.via.u64); #else if (o.via.u64 > ULONG_MAX) fprintf(out, "#", o.type); else fprintf(out, "#", o.type, (unsigned long)o.via.u64); #endif } } #endif #define MSGPACK_CHECKED_CALL(ret, func, aux_buffer, aux_buffer_size, ...) \ ret = func(aux_buffer, aux_buffer_size, __VA_ARGS__); \ if (ret <= 0 || ret >= (int)aux_buffer_size) return 0; \ aux_buffer = aux_buffer + ret; \ aux_buffer_size = aux_buffer_size - ret \ static int msgpack_object_bin_print_buffer(char *buffer, size_t buffer_size, const char *ptr, size_t size) { size_t i; char *aux_buffer = buffer; size_t aux_buffer_size = buffer_size; int ret; for (i = 0; i < size; ++i) { if (ptr[i] == '"') { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\\\""); } else if (isprint((unsigned char)ptr[i])) { if (aux_buffer_size > 0) { memcpy(aux_buffer, ptr + i, 1); aux_buffer = aux_buffer + 1; aux_buffer_size = aux_buffer_size - 1; } } else { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\\x%02x", (unsigned char)ptr[i]); } } return (int)(buffer_size - aux_buffer_size); } int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object o) { char *aux_buffer = buffer; size_t aux_buffer_size = buffer_size; int ret; switch(o.type) { case MSGPACK_OBJECT_NIL: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "nil"); break; case MSGPACK_OBJECT_BOOLEAN: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, (o.via.boolean ? "true" : "false")); break; case MSGPACK_OBJECT_POSITIVE_INTEGER: #if defined(PRIu64) MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIu64, o.via.u64); #else if (o.via.u64 > ULONG_MAX) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "over 4294967295"); } else { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%lu", (unsigned long)o.via.u64); } #endif break; case MSGPACK_OBJECT_NEGATIVE_INTEGER: #if defined(PRIi64) MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIi64, o.via.i64); #else if (o.via.i64 > LONG_MAX) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "over +2147483647"); } else if (o.via.i64 < LONG_MIN) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "under -2147483648"); } else { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", (signed long)o.via.i64); } #endif break; case MSGPACK_OBJECT_FLOAT32: case MSGPACK_OBJECT_FLOAT64: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%f", o.via.f64); break; case MSGPACK_OBJECT_STR: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); if (o.via.str.size > 0) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%.*s", (int)o.via.str.size, o.via.str.ptr); } MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); break; case MSGPACK_OBJECT_BIN: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); MSGPACK_CHECKED_CALL(ret, msgpack_object_bin_print_buffer, aux_buffer, aux_buffer_size, o.via.bin.ptr, o.via.bin.size); MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); break; case MSGPACK_OBJECT_EXT: #if defined(PRIi8) MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "(ext: %" PRIi8 ")", o.via.ext.type); #else MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "(ext: %d)", (int)o.via.ext.type); #endif MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); MSGPACK_CHECKED_CALL(ret, msgpack_object_bin_print_buffer, aux_buffer, aux_buffer_size, o.via.ext.ptr, o.via.ext.size); MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); break; case MSGPACK_OBJECT_ARRAY: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "["); if(o.via.array.size != 0) { msgpack_object* p = o.via.array.ptr; msgpack_object* const pend = o.via.array.ptr + o.via.array.size; MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, *p); ++p; for(; p < pend; ++p) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ", "); MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, *p); } } MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "]"); break; case MSGPACK_OBJECT_MAP: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "{"); if(o.via.map.size != 0) { msgpack_object_kv* p = o.via.map.ptr; msgpack_object_kv* const pend = o.via.map.ptr + o.via.map.size; MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, p->key); MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "=>"); MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, p->val); ++p; for(; p < pend; ++p) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ", "); MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, p->key); MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "=>"); MSGPACK_CHECKED_CALL(ret, msgpack_object_print_buffer, aux_buffer, aux_buffer_size, p->val); } } MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "}"); break; default: // FIXME #if defined(PRIu64) MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "#", o.type, o.via.u64); #else if (o.via.u64 > ULONG_MAX) { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "#", o.type); } else { MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "#", o.type, (unsigned long)o.via.u64); } #endif } return (int)(buffer_size - aux_buffer_size); } #undef MSGPACK_CHECKED_CALL bool msgpack_object_equal(const msgpack_object x, const msgpack_object y) { if(x.type != y.type) { return false; } switch(x.type) { case MSGPACK_OBJECT_NIL: return true; case MSGPACK_OBJECT_BOOLEAN: return x.via.boolean == y.via.boolean; case MSGPACK_OBJECT_POSITIVE_INTEGER: return x.via.u64 == y.via.u64; case MSGPACK_OBJECT_NEGATIVE_INTEGER: return x.via.i64 == y.via.i64; case MSGPACK_OBJECT_FLOAT32: case MSGPACK_OBJECT_FLOAT64: return x.via.f64 == y.via.f64; case MSGPACK_OBJECT_STR: return x.via.str.size == y.via.str.size && memcmp(x.via.str.ptr, y.via.str.ptr, x.via.str.size) == 0; case MSGPACK_OBJECT_BIN: return x.via.bin.size == y.via.bin.size && memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0; case MSGPACK_OBJECT_EXT: return x.via.ext.size == y.via.ext.size && x.via.ext.type == y.via.ext.type && memcmp(x.via.ext.ptr, y.via.ext.ptr, x.via.ext.size) == 0; case MSGPACK_OBJECT_ARRAY: if(x.via.array.size != y.via.array.size) { return false; } else if(x.via.array.size == 0) { return true; } else { msgpack_object* px = x.via.array.ptr; msgpack_object* const pxend = x.via.array.ptr + x.via.array.size; msgpack_object* py = y.via.array.ptr; do { if(!msgpack_object_equal(*px, *py)) { return false; } ++px; ++py; } while(px < pxend); return true; } case MSGPACK_OBJECT_MAP: if(x.via.map.size != y.via.map.size) { return false; } else if(x.via.map.size == 0) { return true; } else { msgpack_object_kv* px = x.via.map.ptr; msgpack_object_kv* const pxend = x.via.map.ptr + x.via.map.size; msgpack_object_kv* py = y.via.map.ptr; do { if(!msgpack_object_equal(px->key, py->key) || !msgpack_object_equal(px->val, py->val)) { return false; } ++px; ++py; } while(px < pxend); return true; } default: return false; } } msgpack-c-6.0.1/cmake/0000755000175000017460000000000014602664033013454 5ustar kondowheelmsgpack-c-6.0.1/cmake/sysdep.h.in0000644000175000017460000001636014602664033015547 0ustar kondowheel/* * MessagePack system dependencies * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_SYSDEP_H #define MSGPACK_SYSDEP_H #include #include #ifndef MSGPACK_ENDIAN_BIG_BYTE #define MSGPACK_ENDIAN_BIG_BYTE @MSGPACK_ENDIAN_BIG_BYTE@ #endif #ifndef MSGPACK_ENDIAN_LITTLE_BYTE #define MSGPACK_ENDIAN_LITTLE_BYTE @MSGPACK_ENDIAN_LITTLE_BYTE@ #endif #if defined(_MSC_VER) && _MSC_VER <= 1800 # define snprintf(buf, len, format,...) _snprintf_s(buf, len, _TRUNCATE, format, __VA_ARGS__) #endif #if defined(_MSC_VER) && _MSC_VER < 1600 typedef signed __int8 int8_t; typedef unsigned __int8 uint8_t; typedef signed __int16 int16_t; typedef unsigned __int16 uint16_t; typedef signed __int32 int32_t; typedef unsigned __int32 uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; # if defined(_WIN64) typedef signed __int64 intptr_t; typedef unsigned __int64 uintptr_t; # else typedef signed __int32 intptr_t; typedef unsigned __int32 uintptr_t; # endif #elif defined(_MSC_VER) // && _MSC_VER >= 1600 # include #else # include # include #endif #if !defined(MSGPACK_DLLEXPORT) #if defined(_MSC_VER) # define MSGPACK_DLLEXPORT __declspec(dllexport) #else /* _MSC_VER */ # define MSGPACK_DLLEXPORT #endif /* _MSC_VER */ #endif #ifdef _WIN32 # if defined(_KERNEL_MODE) # define _msgpack_atomic_counter_header # else # define _msgpack_atomic_counter_header # if !defined(WIN32_LEAN_AND_MEAN) # define WIN32_LEAN_AND_MEAN # endif /* WIN32_LEAN_AND_MEAN */ # endif typedef long _msgpack_atomic_counter_t; #if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64) # define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr) # define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr) #else # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) #endif #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) # if defined(__cplusplus) # define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp" # else # define _msgpack_atomic_counter_header "msgpack/gcc_atomic.h" # endif #else typedef unsigned int _msgpack_atomic_counter_t; # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) #endif #ifdef _WIN32 # ifdef __cplusplus /* numeric_limits::min,max */ # ifdef max # undef max # endif # ifdef min # undef min # endif # endif #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) #include /* __BYTE_ORDER */ # if defined(linux) # include # endif #endif #if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE) #include #endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE) #if MSGPACK_ENDIAN_LITTLE_BYTE # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be16(x) ntohs((uint16_t)x) # else # if defined(ntohs) # define _msgpack_be16(x) ntohs(x) # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) # else # define _msgpack_be16(x) ( \ ((((uint16_t)x) << 8) ) | \ ((((uint16_t)x) >> 8) ) ) # endif # endif # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be32(x) ntohl((uint32_t)x) # else # if defined(ntohl) # define _msgpack_be32(x) ntohl(x) # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) # else # define _msgpack_be32(x) \ ( ((((uint32_t)x) << 24) ) | \ ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ ((((uint32_t)x) >> 24) ) ) # endif # endif # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be64(x) (_byteswap_uint64(x)) # elif defined(bswap_64) # define _msgpack_be64(x) bswap_64(x) # elif defined(__DARWIN_OSSwapInt64) # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) # else # define _msgpack_be64(x) \ ( ((((uint64_t)x) << 56) ) | \ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ ((((uint64_t)x) >> 56) ) ) # endif #elif MSGPACK_ENDIAN_BIG_BYTE # define _msgpack_be16(x) (x) # define _msgpack_be32(x) (x) # define _msgpack_be64(x) (x) #else # error msgpack-c supports only big endian and little endian #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */ #define _msgpack_load16(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be16(*(to)); \ } while (0); #define _msgpack_load32(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be32(*(to)); \ } while (0); #define _msgpack_load64(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be64(*(to)); \ } while (0); #define _msgpack_store16(to, num) \ do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0) #define _msgpack_store32(to, num) \ do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0) #define _msgpack_store64(to, num) \ do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) /* #define _msgpack_load16(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); }) #define _msgpack_load32(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); }) #define _msgpack_load64(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); }) */ #if !defined(__cplusplus) && defined(_MSC_VER) # if !defined(_KERNEL_MODE) # if !defined(FALSE) # define FALSE (0) # endif # if !defined(TRUE) # define TRUE (!FALSE) # endif # endif # if _MSC_VER >= 1800 # include # else # define bool int # define true TRUE # define false FALSE # endif # define inline __inline #endif #ifdef __APPLE__ # include #endif #endif /* msgpack/sysdep.h */ msgpack-c-6.0.1/cmake/CodeCoverage.cmake0000644000175000017460000000362214602664033017007 0ustar kondowheel# Check prereqs FIND_PROGRAM(GCOV_PATH gcov) FIND_PROGRAM(LCOV_PATH lcov) FIND_PROGRAM(GENHTML_PATH genhtml) IF(NOT GCOV_PATH) MESSAGE(FATAL_ERROR "gcov not found! Aborting...") ENDIF() IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX) # Clang version 3.0.0 and greater now supports gcov as well. MESSAGE(STATUS "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") ENDIF() ENDIF() SET(COVERAGE_FLAGS "-g -O0 --coverage") FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) IF(NOT LCOV_PATH) MESSAGE(FATAL_ERROR "lcov not found! Aborting...") ENDIF() IF(NOT GENHTML_PATH) MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") ENDIF() # Setup target ADD_CUSTOM_TARGET(${_targetname} # Cleanup lcov ${LCOV_PATH} --directory . --zerocounters # Run tests COMMAND ${_testrunner} ${ARGV3} # Capturing lcov counters and generating report COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info --base-directory ${CMAKE_SOURCE_DIR} --no-external --quiet COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/test/*' '*/fuzz/*' --output-file ${_outputname}.info.cleaned --quiet COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned --prefix ${CMAKE_SOURCE_DIR} # COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." ) # Show info where to find the report ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD COMMAND ; COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." ) ENDFUNCTION() msgpack-c-6.0.1/cmake/pack_template.h.in0000644000175000017460000006066614602664033017061 0ustar kondowheel/* * MessagePack packing routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_ENDIAN_BIG_BYTE #define MSGPACK_ENDIAN_BIG_BYTE @MSGPACK_ENDIAN_BIG_BYTE@ #endif #ifndef MSGPACK_ENDIAN_LITTLE_BYTE #define MSGPACK_ENDIAN_LITTLE_BYTE @MSGPACK_ENDIAN_LITTLE_BYTE@ #endif #if MSGPACK_ENDIAN_LITTLE_BYTE #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[0] #define TAKE8_32(d) ((uint8_t*)&d)[0] #define TAKE8_64(d) ((uint8_t*)&d)[0] #elif MSGPACK_ENDIAN_BIG_BYTE #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[1] #define TAKE8_32(d) ((uint8_t*)&d)[3] #define TAKE8_64(d) ((uint8_t*)&d)[7] #else #error msgpack-c supports only big endian and little endian #endif #ifndef msgpack_pack_inline_func #error msgpack_pack_inline_func template is not defined #endif #ifndef msgpack_pack_user #error msgpack_pack_user type is not defined #endif #ifndef msgpack_pack_append_buffer #error msgpack_pack_append_buffer callback is not defined #endif #if defined(_MSC_VER) # pragma warning(push) # pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */ #endif /* * Integer */ #define msgpack_pack_real_uint8(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } while(0) #define msgpack_pack_real_uint16(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } while(0) #define msgpack_pack_real_uint32(x, d) \ do { \ if(d < (1<<8)) { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_uint64(x, d) \ do { \ if(d < (1ULL<<8)) { \ if(d < (1ULL<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1ULL<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else if(d < (1ULL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } while(0) #define msgpack_pack_real_int8(x, d) \ do { \ if(d < -(1<<5)) { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } \ } while(0) #define msgpack_pack_real_int16(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } \ } while(0) #define msgpack_pack_real_int32(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<15)) { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_int64(x, d) \ do { \ if(d < -(1LL<<5)) { \ if(d < -(1LL<<15)) { \ if(d < -(1LL<<31)) { \ /* signed 64 */ \ unsigned char buf[9]; \ buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } else { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } else { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ if(d < (1LL<<16)) { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } else { \ if(d < (1LL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } \ } while(0) #ifdef msgpack_pack_inline_func_fixint msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d) { unsigned char buf[2] = {0xcc, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d) { unsigned char buf[3]; buf[0] = 0xcd; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d) { unsigned char buf[5]; buf[0] = 0xce; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d) { unsigned char buf[9]; buf[0] = 0xcf; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d) { unsigned char buf[2] = {0xd0, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d) { unsigned char buf[3]; buf[0] = 0xd1; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d) { unsigned char buf[5]; buf[0] = 0xd2; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d) { unsigned char buf[9]; buf[0] = 0xd3; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } #undef msgpack_pack_inline_func_fixint #endif msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d) { msgpack_pack_real_uint8(x, d); } msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d) { msgpack_pack_real_uint16(x, d); } msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d) { msgpack_pack_real_uint32(x, d); } msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d) { msgpack_pack_real_uint64(x, d); } msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d) { msgpack_pack_real_int8(x, d); } msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d) { msgpack_pack_real_int16(x, d); } msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d) { msgpack_pack_real_int32(x, d); } msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d) { msgpack_pack_real_int64(x, d); } msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d) { #if defined(CHAR_MIN) #if CHAR_MIN < 0 msgpack_pack_real_int8(x, d); #else msgpack_pack_real_uint8(x, d); #endif #else #error CHAR_MIN is not defined #endif } msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d) { msgpack_pack_real_int8(x, d); } msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d) { msgpack_pack_real_uint8(x, d); } #ifdef msgpack_pack_inline_func_cint msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(SHRT_MAX) #if SHRT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif SHRT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(short) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(short) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(INT_MAX) #if INT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif INT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(int) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(int) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LONG_MAX) #if LONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LLONG_MAX) #if LLONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LLONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(USHRT_MAX) #if USHRT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif USHRT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned short) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned short) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(UINT_MAX) #if UINT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif UINT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned int) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned int) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULONG_MAX) #if ULONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULLONG_MAX) #if ULLONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULLONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } #undef msgpack_pack_inline_func_cint #endif /* * Float */ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) { unsigned char buf[5]; union { float f; uint32_t i; } mem; mem.f = d; buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) { unsigned char buf[9]; union { double f; uint64_t i; } mem; mem.f = d; buf[0] = 0xcb; #if defined(TARGET_OS_IPHONE) // ok #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi // https://github.com/msgpack/msgpack-perl/pull/1 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL); #endif _msgpack_store64(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 9); } /* * Nil */ msgpack_pack_inline_func(_nil)(msgpack_pack_user x) { static const unsigned char d = 0xc0; msgpack_pack_append_buffer(x, &d, 1); } /* * Boolean */ msgpack_pack_inline_func(_true)(msgpack_pack_user x) { static const unsigned char d = 0xc3; msgpack_pack_append_buffer(x, &d, 1); } msgpack_pack_inline_func(_false)(msgpack_pack_user x) { static const unsigned char d = 0xc2; msgpack_pack_append_buffer(x, &d, 1); } /* * Array */ msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n) { if(n < 16) { unsigned char d = 0x90 | (uint8_t)n; msgpack_pack_append_buffer(x, &d, 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Map */ msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n) { if(n < 16) { unsigned char d = 0x80 | (uint8_t)n; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Str */ msgpack_pack_inline_func(_str)(msgpack_pack_user x, size_t l) { if(l < 32) { unsigned char d = 0xa0 | (uint8_t)l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(l < 256) { unsigned char buf[2]; buf[0] = 0xd9; buf[1] = (uint8_t)l; msgpack_pack_append_buffer(x, buf, 2); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_str_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Raw (V4) */ msgpack_pack_inline_func(_v4raw)(msgpack_pack_user x, size_t l) { if(l < 32) { unsigned char d = 0xa0 | (uint8_t)l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_v4raw_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Bin */ msgpack_pack_inline_func(_bin)(msgpack_pack_user x, size_t l) { if(l < 256) { unsigned char buf[2]; buf[0] = 0xc4; buf[1] = (uint8_t)l; msgpack_pack_append_buffer(x, buf, 2); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xc5; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_bin_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Ext */ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type) { switch(l) { case 1: { unsigned char buf[2]; buf[0] = 0xd4; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 2: { unsigned char buf[2]; buf[0] = 0xd5; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 4: { unsigned char buf[2]; buf[0] = 0xd6; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 8: { unsigned char buf[2]; buf[0] = 0xd7; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 16: { unsigned char buf[2]; buf[0] = 0xd8; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; default: if(l < 256) { unsigned char buf[3]; buf[0] = 0xc7; buf[1] = (unsigned char)l; buf[2] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 3); } else if(l < 65536) { unsigned char buf[4]; buf[0] = 0xc8; _msgpack_store16(&buf[1], l); buf[3] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 4); } else { unsigned char buf[6]; buf[0] = 0xc9; _msgpack_store32(&buf[1], l); buf[5] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 6); } break; } } msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d) { if ((((int64_t)d->tv_sec) >> 34) == 0) { uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec; if ((data64 & 0xffffffff00000000L) == 0) { // timestamp 32 char buf[4]; uint32_t data32 = (uint32_t)data64; msgpack_pack_ext(x, 4, -1); _msgpack_store32(buf, data32); msgpack_pack_append_buffer(x, buf, 4); } else { // timestamp 64 char buf[8]; msgpack_pack_ext(x, 8, -1); _msgpack_store64(buf, data64); msgpack_pack_append_buffer(x, buf, 8); } } else { // timestamp 96 char buf[12]; _msgpack_store32(&buf[0], d->tv_nsec); _msgpack_store64(&buf[4], d->tv_sec); msgpack_pack_ext(x, 12, -1); msgpack_pack_append_buffer(x, buf, 12); } } #undef msgpack_pack_inline_func #undef msgpack_pack_user #undef msgpack_pack_append_buffer #undef TAKE8_8 #undef TAKE8_16 #undef TAKE8_32 #undef TAKE8_64 #undef msgpack_pack_real_uint8 #undef msgpack_pack_real_uint16 #undef msgpack_pack_real_uint32 #undef msgpack_pack_real_uint64 #undef msgpack_pack_real_int8 #undef msgpack_pack_real_int16 #undef msgpack_pack_real_int32 #undef msgpack_pack_real_int64 #if defined(_MSC_VER) # pragma warning(pop) #endif msgpack-c-6.0.1/CMakeLists.txt0000644000175000017460000002640614602712217015142 0ustar kondowheelif(${CMAKE_VERSION} VERSION_GREATER "3.4") CMAKE_MINIMUM_REQUIRED (VERSION 3.5) else() CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12) IF ((CMAKE_VERSION VERSION_GREATER 3.1) OR (CMAKE_VERSION VERSION_EQUAL 3.1)) CMAKE_POLICY(SET CMP0054 NEW) ENDIF () endif() OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." OFF) OPTION (MSGPACK_GEN_COVERAGE "Enable running gcov to get a test coverage report." OFF) if(MSGPACK_BUILD_TESTS) PROJECT (msgpack-c) else() PROJECT (msgpack-c C) endif() FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.h contents) STRING (REGEX MATCH "#define MSGPACK_VERSION_MAJOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents}) SET (VERSION_MAJOR ${CMAKE_MATCH_1}) STRING (REGEX MATCH "#define MSGPACK_VERSION_MINOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents}) SET (VERSION_MINOR ${CMAKE_MATCH_1}) STRING (REGEX MATCH "#define MSGPACK_VERSION_REVISION *([0-9a-zA-Z_]*)" NULL_OUT ${contents}) SET (VERSION_REVISION ${CMAKE_MATCH_1}) SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}) LIST (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") include(GNUInstallDirs) SET (prefix ${CMAKE_INSTALL_PREFIX}) SET (exec_prefix ${CMAKE_INSTALL_PREFIX}) SET (libdir ${CMAKE_INSTALL_LIBDIR}) SET (includedir ${CMAKE_INSTALL_INCLUDEDIR}) OPTION (MSGPACK_32BIT "32bit compile" OFF) INCLUDE(TestBigEndian) TEST_BIG_ENDIAN(BIGENDIAN) IF (BIGENDIAN) SET(MSGPACK_ENDIAN_BIG_BYTE 1) SET(MSGPACK_ENDIAN_LITTLE_BYTE 0) ELSE () SET(MSGPACK_ENDIAN_BIG_BYTE 0) SET(MSGPACK_ENDIAN_LITTLE_BYTE 1) ENDIF () CONFIGURE_FILE ( cmake/sysdep.h.in include/msgpack/sysdep.h @ONLY ) CONFIGURE_FILE ( cmake/pack_template.h.in include/msgpack/pack_template.h @ONLY ) IF (APPLE) SET(CMAKE_MACOSX_RPATH ON) SET(CMAKE_SKIP_BUILD_RPATH FALSE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) IF ("${isSystemDir}" STREQUAL "-1") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") ENDIF () ENDIF () IF (MSGPACK_32BIT) IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}") SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}") ELSEIF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}") SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}") ENDIF () ENDIF () OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON) IF (MSGPACK_CHAR_SIGN) SET (CMAKE_C_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_C_FLAGS}") ENDIF () IF (DEFINED BUILD_SHARED_LIBS) IF (BUILD_SHARED_LIBS) IF (DEFINED MSGPACK_ENABLE_SHARED AND NOT MSGPACK_ENABLE_SHARED) MESSAGE(WARNING "MSGPACK_ENABLE_SHARED is overridden to ON by BUILD_SHARED_LIBS") ENDIF () SET (MSGPACK_ENABLE_SHARED ON) IF (DEFINED MSGPACK_ENABLE_STATIC AND MSGPACK_ENABLE_STATIC) MESSAGE(WARNING "MSGPACK_ENABLE_STATIC is overridden to OFF by BUILD_SHARED_LIBS") ENDIF () SET (MSGPACK_ENABLE_STATIC OFF) ELSE () IF (DEFINED MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_SHARED) MESSAGE(WARNING "MSGPACK_ENABLE_SHARED is overridden to OFF by BUILD_SHARED_LIBS") ENDIF () SET (MSGPACK_ENABLE_SHARED OFF) IF (DEFINED MSGPACK_ENABLE_STATIC AND NOT MSGPACK_ENABLE_STATIC) MESSAGE(WARNING "MSGPACK_ENABLE_STATIC is overridden to ON by BUILD_SHARED_LIBS") ENDIF () SET (MSGPACK_ENABLE_STATIC ON) ENDIF () ELSE () IF (NOT DEFINED MSGPACK_ENABLE_SHARED) SET (MSGPACK_ENABLE_SHARED ON) ENDIF () IF (NOT DEFINED MSGPACK_ENABLE_STATIC) SET (MSGPACK_ENABLE_STATIC ON) ENDIF () SET (BUILD_SHARED_LIBS ${MSGPACK_ENABLE_SHARED}) ENDIF () INCLUDE (Files.cmake) CONFIGURE_FILE ( msgpack-c.pc.in msgpack-c.pc @ONLY ) IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC) ADD_LIBRARY (msgpack-c ${msgpack-c_SOURCES} ${msgpack-c_HEADERS} ) SET_TARGET_PROPERTIES (msgpack-c PROPERTIES SOVERSION 2 VERSION 2.0.0) TARGET_INCLUDE_DIRECTORIES (msgpack-c PUBLIC $ $ $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) ENDIF () IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC) ADD_LIBRARY (msgpack-c-static STATIC ${msgpack-c_SOURCES} ${msgpack-c_HEADERS} ) TARGET_INCLUDE_DIRECTORIES (msgpack-c-static PUBLIC $ $ $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) SET_TARGET_PROPERTIES (msgpack-c-static PROPERTIES OUTPUT_NAME "msgpack-c") IF (MSGPACK_ENABLE_SHARED) IF (MSVC) SET_TARGET_PROPERTIES (msgpack-c PROPERTIES IMPORT_SUFFIX "_import.lib") ELSEIF (MINGW) SET_TARGET_PROPERTIES (msgpack-c PROPERTIES IMPORT_SUFFIX ".dll.a") ENDIF () ENDIF () ENDIF () IF (MSGPACK_GEN_COVERAGE) IF (NOT MSGPACK_BUILD_TESTS) MESSAGE(FATAL_ERROR "Coverage requires -DMSGPACK_BUILD_TESTS=ON") ENDIF () STRING(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_CMAKE_BUILD_TYPE) IF (NOT "${UPPER_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") MESSAGE(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug") ENDIF () INCLUDE(CodeCoverage) SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}") SETUP_TARGET_FOR_COVERAGE(coverage make coverage test) ENDIF () IF (MSGPACK_BUILD_TESTS) ENABLE_TESTING () list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") # MEMORYCHECK_COMMAND_OPTIONS needs to place prior to CTEST_MEMORYCHECK_COMMAND SET (MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=definite,possible --error-exitcode=1") FIND_PROGRAM(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) INCLUDE(Dart) ADD_SUBDIRECTORY (test) ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC) SET_PROPERTY (TARGET msgpack-c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -DPIC") ENDIF () IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC) SET_PROPERTY (TARGET msgpack-c-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra" ) ENDIF () ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC) SET_PROPERTY (TARGET msgpack-c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags") ENDIF () IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC) SET_PROPERTY (TARGET msgpack-c-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags") ENDIF () ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_C_FLAGS MATCHES "/W[0-4]") STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") ELSE () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") ENDIF () ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_C_FLAGS MATCHES "/W[0-4]") STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") ELSE () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") ENDIF () ENDIF () IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC90" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC10") SET_SOURCE_FILES_PROPERTIES(${msgpack-c_SOURCES} PROPERTIES LANGUAGE C) ENDIF () IF ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "sparc") SET (CMAKE_C_FLAGS "-DMSGPACK_ZONE_ALIGN=8 ${CMAKE_C_FLAGS}") ENDIF () IF (NOT DEFINED CMAKE_INSTALL_BINDIR) SET(CMAKE_INSTALL_BINDIR bin) ENDIF () IF (NOT DEFINED CMAKE_INSTALL_LIBDIR) SET(CMAKE_INSTALL_LIBDIR lib) ENDIF () IF (MSGPACK_BUILD_EXAMPLES) ADD_SUBDIRECTORY (example) ENDIF () IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC) SET (MSGPACK_INSTALLTARGETS msgpack-c) ENDIF () IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC) LIST (APPEND MSGPACK_INSTALLTARGETS msgpack-c-static) ENDIF () INSTALL (TARGETS ${MSGPACK_INSTALLTARGETS} EXPORT msgpack-c-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) FOREACH (file ${msgpack-c_common_HEADERS}) GET_FILENAME_COMPONENT (dir ${file} PATH) INSTALL (FILES ${file} DESTINATION ${dir}) ENDFOREACH () FOREACH (file ${msgpack-c_configured_HEADERS}) GET_FILENAME_COMPONENT (dir ${file} PATH) INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/${file} DESTINATION ${dir}) ENDFOREACH () IF (NOT MSVC) INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/msgpack-c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ENDIF () # Doxygen FIND_PACKAGE (Doxygen) IF (DOXYGEN_FOUND) LIST (APPEND Doxyfile_c_CONTENT COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.h" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_c" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c COMMAND ${CMAKE_COMMAND} -E echo "STRIP_FROM_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c ) IF (DOXYGEN_DOT_FOUND) LIST (APPEND Doxyfile_c_CONTENT COMMAND ${CMAKE_COMMAND} -E echo "HAVE_DOT = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c ) ENDIF () ADD_CUSTOM_TARGET ( doxygen ${Doxyfile_c_CONTENT} COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c VERBATIM ) ENDIF () INCLUDE (CMakePackageConfigHelpers) SET (CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/msgpack-c") WRITE_BASIC_PACKAGE_VERSION_FILE ( msgpack-c-config-version.cmake VERSION ${VERSION} COMPATIBILITY SameMajorVersion ) IF (NOT CMAKE_VERSION VERSION_LESS 3.0) EXPORT (EXPORT msgpack-c-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/msgpack-c-targets.cmake" ) ENDIF () CONFIGURE_PACKAGE_CONFIG_FILE (msgpack-c-config.cmake.in msgpack-c-config.cmake INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) INSTALL (EXPORT msgpack-c-targets FILE msgpack-c-targets.cmake DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) INSTALL ( FILES "${CMAKE_CURRENT_BINARY_DIR}/msgpack-c-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/msgpack-c-config-version.cmake" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) msgpack-c-6.0.1/Files.cmake0000644000175000017460000000167314602664031014445 0ustar kondowheel# Source files SET (msgpack-c_SOURCES src/objectc.c src/unpack.c src/version.c src/vrefbuffer.c src/zone.c ) # Header files SET (msgpack-c_common_HEADERS include/msgpack.h include/msgpack/fbuffer.h include/msgpack/gcc_atomic.h include/msgpack/object.h include/msgpack/pack.h include/msgpack/pack_define.h include/msgpack/sbuffer.h include/msgpack/timestamp.h include/msgpack/unpack.h include/msgpack/unpack_define.h include/msgpack/unpack_template.h include/msgpack/util.h include/msgpack/version.h include/msgpack/version_master.h include/msgpack/vrefbuffer.h include/msgpack/zbuffer.h include/msgpack/zone.h ) # Header files will configured SET (msgpack-c_configured_HEADERS include/msgpack/pack_template.h include/msgpack/sysdep.h ) # All header files LIST (APPEND msgpack-c_HEADERS ${msgpack-c_common_HEADERS} ${msgpack-c_configured_HEADERS} ) msgpack-c-6.0.1/NOTICE0000644000175000017460000000064314602664031013301 0ustar kondowheelThis product bundles Boost Predef and Boost Preprocessor. They are distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) For details, see the following files: external/boost/predef include/msgpack/predef.h include/msgpack/predef/* external/boost/preprocessor include/msgpack/preprocessor.hpp include/msgpack/preprocessor/* msgpack-c-6.0.1/Doxyfile0000644000175000017460000017765314602664031014123 0ustar kondowheel# Doxyfile 1.6.2 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project # # All text after a hash (#) is considered a comment and will be ignored # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = "MessagePack" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = doc # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output # format and will distribute the generated files over these directories. # Enabling this option can be useful when feeding doxygen a huge amount of # source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator # that is used to form the text in various listings. Each string # in this list, if found as the leading text of the brief description, will be # stripped from the text and the result after processing the whole list, is # used as the annotated text. Otherwise, the brief description is used as-is. # If left blank, the following values are used ("$name" is automatically # replaced with the name of the entity): "The $name class" "The $name widget" # "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = YES # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the # path to strip. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells # the reader which header file to include in order to use a class. # If left blank only the name of the header file containing the class # definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful is your file systems # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style # comment as the brief description. If set to NO, the comments # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. # The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 8 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java # sources only. Doxygen will then generate output that is more tailored for # Java. For instance, namespaces will be presented as packages, qualified # scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources only. Doxygen will then generate output that is more tailored for # Fortran. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for # VHDL. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it parses. # With this tag you can assign which parser to use for a given extension. # Doxygen has a built-in mapping, but you can override or extend it using this tag. # The format is ext=language, where ext is a file extension, and language is one of # the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, # Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat # .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), # use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. EXTENSION_MAPPING = # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. # Doxygen will parse them like normal C++ but will assume all classes use public # instead of private inheritance when no explicit protection keyword is present. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate getter # and setter methods for a property. Setting this option to YES (the default) # will make doxygen to replace the get and set methods by a property in the # documentation. This will only work if the methods are indeed getting or # setting a simple type. If this is not the case, or you want to show the # methods anyway, you should set this option to NO. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically # be useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. TYPEDEF_HIDES_STRUCT = NO # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to # determine which symbols to keep in memory and which to flush to disk. # When the cache is full, less often used symbols will be written to disk. # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time # causing a significant performance penality. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on # a logarithmic scale so increasing the size by one will roughly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in # the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default # anonymous namespace are hidden. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all # friend (class|struct|union) declarations. # If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any # documentation blocks found inside the body of a function. # If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen # will list include files with double quotes in the documentation # rather than with sharp brackets. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the # brief documentation of file, namespace and class members alphabetically # by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, # not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or # disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or define consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and defines in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES # If the sources in your project are distributed over multiple directories # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy # in the documentation. The default is NO. SHOW_DIRECTORIES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the # Namespaces page. # This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by # doxygen. The layout file controls the global structure of the generated output files # in an output format independent way. The create the layout file that represents # doxygen's defaults, run doxygen with the -l option. You can optionally specify a # file name after the option, if omitted DoxygenLayout.xml will be used as the name # of the layout file. LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some # parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be abled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = NO # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. Optionally the format may contain # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # also the default input encoding. Doxygen uses libiconv (or the iconv built # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for # the list of possible encodings. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 FILE_PATTERNS = *.hpp *.h # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. #RECURSIVE = NO RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. Note that the wildcards are matched # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. # If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. # Doxygen will compare the file name with each pattern and apply the # filter if there is a match. # The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER # is applied to all files. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = YES # If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = YES # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will # link to the source code. # Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source # tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = NO # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for # each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet. Note that doxygen will try to copy # the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! HTML_STYLESHEET = # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting # this to NO can help when comparing the output of multiple runs. HTML_TIMESTAMP = NO # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. For this to work a browser that supports # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). HTML_DYNAMIC_SECTIONS = NO # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). # To create a documentation set, doxygen will generate a Makefile in the # HTML output directory. Running make will produce the docset in that # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. GENERATE_DOCSET = NO # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the # feed. A documentation feed provides an umbrella under which multiple # documentation sets from a single provider (such as a company or product suite) # can be grouped. DOCSET_FEEDNAME = "Doxygen generated docs" # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that # should uniquely identify the documentation set bundle. This should be a # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen # will append .docset to the name. DOCSET_BUNDLE_ID = org.doxygen.Project # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be # written to the html output directory. CHM_FILE = # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can # be used to specify the location (absolute path including file name) of # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. HHC_LOCATION = # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING # is used to encode HtmlHelp index (hhk), content (hhc) and project file # content. CHM_INDEX_ENCODING = # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER # are set, an additional index file will be generated that can be used as input for # Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated # HTML documentation. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can # be used to specify the file name of the resulting .qch file. # The path specified is relative to the HTML output folder. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#virtual-folders QHP_VIRTUAL_FOLDER = doc # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. # For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see # Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's # filter section matches. # Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can # be used to specify the location of Qt's qhelpgenerator. # If non-empty doxygen will try to run qhelpgenerator on the generated # .qhp file. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files # will be generated, which together with the HTML files, form an Eclipse help # plugin. To install this plugin and make it available under the help contents # menu in Eclipse, the contents of the directory containing the HTML and XML # files needs to be copied into the plugins directory of eclipse. The name of # the directory within the plugins directory should be the same as # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before the help appears. GENERATE_ECLIPSEHELP = NO # A unique identifier for the eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have # this name. ECLIPSE_DOC_ID = org.doxygen.Project # The DISABLE_INDEX tag can be used to turn on/off the condensed index at # top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO # This tag can be used to set the number of enum values (range [1..20]) # that doxygen will group on one line in the generated HTML documentation. ENUM_VALUES_PER_LINE = 4 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. # If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). # Windows users are probably better off using the HTML help feature. GENERATE_TREEVIEW = NO # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, # and Class Hierarchy pages using a tree view instead of an ordered list. USE_INLINE_TREES = NO # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. FORMULA_FONTSIZE = 10 # When the SEARCHENGINE tag is enabled doxygen will generate a search box for the HTML output. The underlying search engine uses javascript # and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) there is already a search function so this one should # typically be disabled. For large projects the javascript based search engine # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be implemented using a PHP enabled web server instead of at the web client using Javascript. Doxygen will generate the search PHP script and index # file to put on the web server. The advantage of the server based approach is that it scales better to large projects and allows full text search. The disadvances is that it is more difficult to setup # and does not have live searching capabilities. SERVER_BASED_SEARCH = NO #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. # Note that when enabling USE_PDFLATEX this option is only used for # generating bitmaps for formulas in the HTML output, but not in the # Makefile that is written to the output directory. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to # generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, a4wide, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not # include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO # If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER. LATEX_SOURCE_CODE = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = NO # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml # The XML_SCHEMA tag can be used to specify an XML schema, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_SCHEMA = # The XML_DTD tag can be used to specify an XML DTD, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_DTD = # If the XML_PROGRAMLISTING tag is set to YES Doxygen will # dump the program listings (including syntax highlighting # and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will # generate an AutoGen Definitions (see autogen.sf.net) file # that captures the structure of the code including all # documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES Doxygen will # generate a Perl module file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES Doxygen will generate # the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be # nicely formatted so it can be parsed by a human reader. # This is useful # if you want to understand what is going on. # On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. # This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. To prevent a macro definition from being # undefined via #undef or recursively expanded use the := operator # instead of the = operator. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all function-like macros that are alone # on a line, have an all uppercase name, and do not end with a semicolon. Such # function macros are typically used for boiler-plate code, and will confuse # the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- # The TAGFILES option can be used to specify one or more tagfiles. # Optionally an initial location of the external documentation # can be added for each tagfile. The format of a tag file without # this location is as follows: # # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # # TAGFILES = file1=loc1 "file2 = loc2" ... # where "loc1" and "loc2" can be relative or absolute paths or # URLs. If a location is present for each tag, the installdox tool # does not have to be run to correct the links. # Note that each tag file must have a unique name # (where the name does NOT include the path) # If a tag file is not located in the directory in which doxygen # is run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed # in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that # this option is superseded by the HAVE_DOT option below. This is only a # fallback. It is recommended to install and use dot, since it yields more # powerful graphs. CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. MSCGEN_PATH = # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = NO # By default doxygen will write a font called FreeSans.ttf to the output # directory and reference it in all dot files that doxygen generates. This # font does not include all possible unicode characters however, so when you need # these (or just want a differently looking font) you can specify the font name # using DOT_FONTNAME. You need need to make sure dot is able to find the font, # which can be done by putting it in a standard location or by setting the # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory # containing the font. DOT_FONTNAME = FreeSans # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. # The default size is 10pt. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the output directory to look for the # FreeSans.ttf font (which doxygen will put there itself). If you specify a # different font using DOT_FONTNAME you can set the path where dot # can find it using this tag. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = NO # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = NO # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH and HAVE_DOT options are set to YES then # doxygen will generate a call dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable call graphs # for selected functions only using the \callgraph command. CALL_GRAPH = NO # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then # doxygen will generate a caller dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable caller # graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are png, jpg, or gif # If left blank png will be used. DOT_IMAGE_FORMAT = png # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is # visualized by representing a node as a red box. Note that doxygen if the # number of direct children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large # code bases. Also note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not # seem to support this out of the box. Warning: Depending on the platform used, # enabling this option may lead to badly anti-aliased labels on the edges of # a graph (i.e. they become hard to read). DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = NO # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES msgpack-c-6.0.1/msgpack-c.pc.in0000644000175000017460000000035714602664031015175 0ustar kondowheelprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: MessagePack Description: Binary-based efficient object serialization library Version: @VERSION@ Libs: -L${libdir} -lmsgpack-c Cflags: -I${includedir} msgpack-c-6.0.1/AUTHORS0000644000175000017460000000000014602712313013425 0ustar kondowheelmsgpack-c-6.0.1/README.md0000644000175000017460000000767314602712217013666 0ustar kondowheel`msgpack` for C =================== Version 6.0.1 [![Build Status](https://github.com/msgpack/msgpack-c/workflows/CI/badge.svg?branch=c_master)](https://github.com/msgpack/msgpack-c/actions) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/c_master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/c_master) [![codecov](https://codecov.io/gh/msgpack/msgpack-c/branch/c_master/graph/badge.svg)](https://codecov.io/gh/msgpack/msgpack-c/branch/c_master) It's like JSON but smaller and faster. Overview -------- [MessagePack](http://msgpack.org/) is an efficient binary serialization format, which lets you exchange data among multiple languages like JSON, except that it's faster and smaller. Small integers are encoded into a single byte and short strings require only one extra byte in addition to the strings themselves. Example ------- ```c #include #include int main(void) { /* msgpack::sbuffer is a simple buffer implementation. */ msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); /* serialize values into the buffer using msgpack_sbuffer_write callback function. */ msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* deserialize the buffer into msgpack_object instance. */ /* deserialized object is valid during the msgpack_zone instance alive. */ msgpack_zone mempool; msgpack_zone_init(&mempool, 2048); msgpack_object deserialized; msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); /* print the deserialized object. */ msgpack_object_print(stdout, deserialized); puts(""); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); return 0; } ``` See [`QUICKSTART-C.md`](./QUICKSTART-C.md) for more details. Usage ----- ### Building and Installing #### Install from git repository ##### Using the Terminal (CLI) You will need: - `gcc >= 4.1.0` - `cmake >= 2.8.0` How to build: $ git clone https://github.com/msgpack/msgpack-c.git $ cd msgpack-c $ git checkout c_master $ cmake . $ make $ sudo make install How to run tests: In order to run tests you must have the [GoogleTest](https://github.com/google/googletest) framework installed. If you do not currently have it, install it and re-run `cmake`. Then: $ make test When you use the C part of `msgpack-c`, you need to build and link the library. By default, both static/shared libraries are built. If you want to build only static library, set `BUILD_SHARED_LIBS=OFF` to cmake. If you want to build only shared library, set `BUILD_SHARED_LIBS=ON`. #### GUI on Windows Clone msgpack-c git repository. $ git clone https://github.com/msgpack/msgpack-c.git or using GUI git client. e.g.) tortoise git https://code.google.com/p/tortoisegit/ 1. Checkout to c_master branch 2. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html). 3. Set 'Where is the source code:' text box and 'Where to build the binaries:' text box. 4. Click 'Configure' button. 5. Choose your Visual Studio version. 6. Click 'Generate' button. 7. Open the created msgpack.sln on Visual Studio. 8. Build all. ### Documentation You can get additional information including the tutorial on the [wiki](https://github.com/msgpack/msgpack-c/wiki). Contributing ------------ `msgpack-c` is developed on GitHub at [msgpack/msgpack-c](https://github.com/msgpack/msgpack-c). To report an issue or send a pull request, use the [issue tracker](https://github.com/msgpack/msgpack-c/issues). Here's the list of [great contributors](https://github.com/msgpack/msgpack-c/graphs/contributors). License ------- `msgpack-c` is licensed under the Boost Software License, Version 1.0. See the [`LICENSE_1_0.txt`](./LICENSE_1_0.txt) file for details. msgpack-c-6.0.1/LICENSE_1_0.txt0000644000175000017460000000247214602664031014661 0ustar kondowheelBoost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. msgpack-c-6.0.1/ChangeLog0000644000175000017460000004305114602712313014144 0ustar kondowheel# 2024-04-02 version 6.0.1 * Improve CI environment (#1061, #1091, #1109) * Improve build system (#1060, #1069, #1108) # 2023-03-02 version 6.0.0 * Remove C++ requirement if test is disabled (#1055) ## << breaking changes >> * Change CMake package name of C library to msgpack-c (#1053) Unified all C package, library, cmake, tarball name become msgpack-c. # 2023-01-10 version 5.0.0 * Add additional address sanitizer for CI. (#1023) ## << breaking changes >> * Change CMake package name of C library to msgpackc (#1044, #1049) # 2021-08-01 version 4.0.0 * Fix and improve alignment logic (#962) * Fix iovec name conflict (#953) * Fix empty string print (#942) * Fix buffer ptr size (#899) * Fix UB. Check null pointer before using memcpy() (#890) * Improve CI environment (#885, #899) ## << breaking changes >> * Separate C part of the msgpack-c from C/C++ mixed msgpack-c (#876, #878) # 2020-06-05 version 3.3.0 * Add json example for C (#870) * Add both header and body packing functions for C (#870) * Set default ref_size and chunk_size to vrefbuffer (#865) * Add examples (#861) * Improve build system (#839, #842) * Improve tests (#829) * Improve documents (#828) * Remove some warnings (#827, #851, #871) * Improve CI environment (#824, #831, #833, #834, #846, #860, 874) # 2019-12-10 version 3.2.1 * Fix snprintf return value checking (#821) * Remove some warnings (#819) * Fix fbuffer result checking (#812) * Fix temporary object handling (#807) * Improve cmake support (#804) * Fix invalid `int main` parameter (#800) * Improve supporting platform (#797, #817) * Fix ZLIB error handling (#795) * Remove unused variable (#793) * Improve integer overflow checking (#792) # 2019-05-27 version 3.2.0 * Fix invalid include (#783) * Add timespec support (#781) * Fix unchecked fnprintf on C (#780) * Improve integer overflow checking on C (#776) * Fix warnings on `-Wconversion` (#770, #777, #784) * Fix invalid passed by value on aligned_zone_size_visitor (#764) * Improve windows support (#757, #779) * Fix msgpack::object size caluclation error (#754) * Fix memory error on example code (#753) * Fix redundant memory allocation on C (#747) * Fix msgpack::type::tuple base class conversion (#743) # 2018-09-09 version 3.1.1 * Add force endian set functionality (#736) * Fix vrefbuffer memory management problem (#733) * Fix msvc specific problem (#731, #732) * Update boost from 1.61.0 to 1.68.0 (#730) * Fix msgpack_timestamp type mismatch bug (#726) # 2018-08-10 version 3.1.0 * Improve documents (#687, #718) * Add fuzzer support (#689) * Fix msgpack::object union member access bug (#694) * Improve cross platform configuration (#704) * Fix out of range dereference bug of EXT (#705) * Add timestamp support. std::chrono::system_clock::time_point is mapped to TIMESTAMP (#706) * Add minimal timestamp support for C. The type `msgpack_timestamp` and the function `msgpack_object_to_timestamp()` are introduced (#707) * Improve MSGPACK_DEFINE family name confliction probability (#710) * Add no static-library build option (BUILD_SHARED_LIBS=ON) (#713, #717, #722) * Add header only cmake target (#721) * Add `std::byte` adaptor (#719) * Remove some warnings (#720) # 2018-05-12 version 3.0.1 * Add fuzz directory to release tar ball (#686) * Add include file checking for X-Code (#683) # 2018-05-09 version 3.0.0 ## << breaking changes >> * Change offset parameter updating rule. If parse error happens, offset is updated to the error position. (#639, #666) ## << other updates >> * Improve cross platform configuration (#655, #677) * Improve build system (#647) * Improve user class adaptor (#645, #673) * Improve msgpack::object visitation logic (#676) * Remove some warnings (#641, 659) * Add `->` and `*` operators to object_handle (#635) * Improve CI environment (#631, #634, #643, #657, #662, #668) * Improve documents (#630, #661) * Refactoring (#670) * Add OSS-Fuzz support (#672, #674, #675, #678) # 2017-08-04 version 2.1.5 * Improve cross platform configuration (#624) * Add boost asio examples (including zlib) (#610) * Remove some warnings (#611) * Fix unpack visitor to treat float32/64 correctly (#613) * Improve documents (#616) * Fix alignment problem on some platform (#617, #518) * Fix conflict std::tuple, std::pair, and boost::fusion::sequence problem (#619) # 2017-08-03 version 2.1.4 (Invalid) * See https://github.com/msgpack/msgpack-c/issues/623 # 2017-06-15 version 2.1.3 * Improve build system (#603) * Add C++17 adaptors `std::optional` and `std::string_view`. (#607, #608) * Improve cross platform configuration (#601) * Remove some warnings (#599, #602, #605) # 2017-06-07 version 2.1.2 * Improve documents (#565) * Fix empty map parse bug (#568) * Improve build system (#569, #570, #572, #579, #591, #592) * Remove some warnings (#574, #578, #586, #588) * Improve cross platform configuration (#577, #582) * Add cmake package config support (#580) * Fix streaming unpack bug (#585) # 2017-02-04 version 2.1.1 * Fix unpacker's buffer management bug (#561) * Add boost string_view adaptor (#558) * Remove some warnings (#557, #559) * Improve coding style (#556) # 2017-01-10 version 2.1.0 ## << breaking changes >> * Fix object internal data type is float if msgpack format is float32 (#531) ## << recommended changes >> * Add `FLOAT64` type. Please use it instead of `DOUBLE` (#531) * Add `FLOAT32` type. Please use it instead of `FLOAT` (#531) ## << other updates >> * Add iterator based parse/unpack function(experimental) (#553) * Add `[[deprecated]]` attribute for C++14 (#552) * Fix `msgpack_unpack()` return code (#548) * Fix integer overflow (#547, #549, #550) * Add example codes (#542) * Add MSGPACK_NVP. You can use not only variable name but also any strings (#535) * Fix and Improve build system (#532, #545) * Fix `gcc_atomic.hpp` include path (#529, #530) * Improve CI environment (#526) * Improve documents (#524) * Add msgpack_unpacker_next_with_size() function (#515) * Fix `as()` applying condition (#511) * Fix fbuffer write (#504) * Add gcc bug workaround (#499) * Improve object print (#497, #500, #505, #533) * Remove some warnings (#495, #506, #508, #513, #528, #538, #545) # 2016-06-25 version 2.0.0 ## << breaking changes >> * Removed autotools support. Use cmake instead (#476, #479) * Removed pointer version of msgpack::unpack APIs. Use reference version instead (#453) * Removed MSGPACK_DISABLE_LEGACY_CONVERT. msgpack::object::convert(T*) is removed by default. Use msgpack::object::convert(T&) instead (#451) * Removed msgpacl::type::nil. Use nil_t or define MSGPACK_USE_LECACY_NIL (#444) * Removed std::string to msgpack::object conversion (#434) ## << recommended changes >> * Replaced msgpack::unpacked with msgpack::object_handle. msgpack::unpacked is kept as a typedef of msgpack::object_handle. (#448) ## << other updates >> * Add strict size checking adaptor. Relaxed tuple conversion (#489) * Fix and Improve example codes (#487) * Add C++/CLI support for nullptr (#481) * Update the boost libraries that are contained by msgpack-c (#475) * Fix gcc_atomic.hpp location (#474) * Add C-Style array support (#466, #488) * Fix include file dependency (#464) * Add a visitor version of unpack API (#461) * Fix JSON string conversion from "nil" to "null" (#458) * Fix and Improve build system (#455, #471, #473, #486, #491) * Fix comments (#452) * Fix unintentional msgpack::zone moving problem (#447) * Fix operator>> and << for msgpack::object (#443) * Fix C++03 msgpack::zone::clear() memory access violation bug (#441) * Fix TARGET_OS_IPHONE checking (#436) * Fix invalid front() call for empty container (#435) * Fix compile error on g++6 (C++11 only) (#426, #430) * Fix zone size expansion logic (#423) * Fix wrong hader file dependency (#421) * Fix msvc specific problem (#420) * Add v2 API support (#415) # 2016-01-22 version 1.4.0 ## << recommended changes >> * Define [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140), then `msgpack::type::nil` is replaced by with `msgpack::type::nil_t` (#408, #411, #412). Replace `msgpack::type::nil` with `msgpack::type::nil_t` in client codes. `msgpack::type::nil` will be removed on the version 2.0.0. * Define [MSGPACK_DISABLE_LEGACY_CONVERT](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_convert-since-140), then `msgpack::object::convert(T*)` is removed (#410). Replace calling `msgpack::bojectconvert(T*)` with `msgpack::bojectconvert(T&)` in client codes as follows: ```C++ int i; obj.convert(&i); // before ``` ```C++ int i; obj.convert(i); // after ``` `msgpack::object::convert(T*)` will be removed on the version 2.0.0. Define the macros above as follows when you compile C++ codes that use msgpack-c: ``` g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT your_code.cpp ``` You can compile existing codes without defining macros above but I recommend defining them and updating your codes to fix the issues #408, #411, #412, #399, and #410. It is also a good preparation for the version 2.0.0. ## << other updates >> * Improve documents (#387, #407) * Remove C++ version library (#394, #402) * Add Doxyfile and ChangeLog to the distribution package (#397) * Add signed/unsigned char test to travis-ci (#398) * Remove some warnings (#400, #401, #409) * Fix endian checking. (#404) # 2015-11-21 version 1.3.0 * Change the license from the Apache License Version 2.0 to the Boost Software License, Version 1.0.(#386) * Remove some warnings (#365) * Add std::reference_wrapper support(#373, #384) * Improve tests (#375, #378, #379, #380) * Fix msvc specific problem (#376, #383) * Fix typos (#381) # 2015-09-04 version 1.2.0 ## << breaking changes >> * Change std::vector and std::array mapped to BIN instead of ARRAY (#243) * Remove redundant copy (#285) ## << other updates >> * Add array_ref to map to ARRAY (#243) * Add variant type and adaptor (#349) * Add object::convert_if_not_nil() (#357) * Fix invalid offset update (#354) * Add C++11 support on MSVC2015(#339, #347) * Fix and Improve build system (#346, #350, #361, #363) * Import Boost.Preprocessor as a part of msgpack-c (#312) * Fix OSX with libc++ specific errors (#334, #362) * Add customized containers support (#330) * Add std::unique_ptr and std::shared_ptr support (#329) * Add missing install files (#328) * Add shared/static library switching option (#316) * Improve no throw description on C++11 (#313) * Import Boost.Predef as a part of msgpack-c (#312) * Add map based serialize support (#306) * Add Boost.Fusion support (#305) * Add v4 format RAW support (#304) * Fix zbuffer with empty string problem (#303) * Add non default constructible class support (#302, #324, #327, #331, #332, #345) * Add inline keyword to function (template) (#299) * Add EXT type supporting classes (#292, #308) * Fix raw_ref != comparison (#290) * Add object deep copy (#288) * Remove some warnings (#284, #322, #323, #335) * Improve compiler version checking (#283) * Add return value to object::convert() (#282) * Improve move semantic support in C++11 (#279, #353) * Add Boost.StringRef support (#278) * Improve CI environment (#276, #294, #338) * Add converting to JSON (#274, #301) * Fix iOS specific problem (#270) * Improve doxtgen document generation (#269) * Add Boost.Optional support (#268) * Fix msvc specific problem (#267, #295) * Add base class serialization. (#265, #277) * Add and improve examples. (#264, #310, #311, #341, #342, #344) * Fix wiki URL. (#263) # 2015-04-03 version 1.1.0 ## << breaking changes >> * Remove msgpack_fwd.hpp * Improve user types adaptation mechanism (#262) Since version 1.0.0, users need to obey the correct include order. However, it is very difficult to maintain the correct order in big projects. version 1.1.0 removed this order. Users don't need to care about include order. Migration guide from 1.0.x to 1.1.0 has been written. See https://github.com/msgpack/msgpack-c/wiki ## << other updates >> * Fix vector size check (#251) * Fix inttypes.h inclusion on MSVC (#257) * Support documents generation by Doxygen (#259) * Remove C99 style variable declaration (#253) * Improve documents (https://github.com/msgpack/msgpack-c/wiki) # 2015-03-22 version 1.0.1: * Fix compilation error on Mac 10.9 (#244) * Fix typos in documents (#240) * Update CHANGELOG.md for version 1.0.0 (#242) * Fix erb templates for the next code generation (#239) # 2015-03-10 version 1.0.0: * Support msgpack v5 format (str, bin, and ext) https://github.com/msgpack/msgpack/blob/master/spec.md (#142) * Support std::tuple, std::forward_list, std::array, std::unordered_set, std::unordered_map on C++11. tr1 unordered containers are still supported (#53, #130, #137, #154, #169) * Update msgpack-c as a header-only library on C++ (#142) * Move include directory (#142) * Update the name of float format family on msgpack::object from 'dec' to 'f64' (#194) * Remove existing elements on associative containers when unpacking (#127) * Add an API versioning functionality https://github.com/msgpack/msgpack-c/wiki/cpp_versioning (#139) * Add C++11 enum class support (#205) * Map std::vector and std::array to BIN (#100) * Map '\0' teminated char* and char const* to STR (#206) * Add the new parameter on unpacking functions and classes to limit msgpack's bytestream size (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#limit-size-of-elements) (#175) * Add the copy or reference choosing function on unpack() and unpacker (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#memory-management) * Add the new unpack() overloads for C++11 https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker (#128) * Add a msgpack::object::with_zone (deep) copying function (#133, #163) * Remove the compile-time defined limit of msgpack nest level on C++ (#218) * Add the new unpack() overloads that use an existing zone (#201) * Add the range-based for loop support on msgpack object array and map (#203) * Add msgpack revision getter function for 'revision' (#237) * Support EXT for C (#118, #129) * Fix unpacking buffer allocation problem when malformed data is given (#160, #185) * Add dll exporting function on MSVC (#162) * Fix msgpack::zone::allocate_no_align(). Now it allocates the memory that is not aligned as expected (#171) * Improve documents (https://github.com/msgpack/msgpack-c/wiki) * Other bug fixes and refactoring: #62, #91, #95, #97, #107, #109, #113, #117, #119, #121, #122, #123, #126, #131, #136, #138, #140, #143, #145, #146, #150, #151, #152, #156, #157, #158, #161, #165, #170, #172, #179, #180, #181, #182, #183, #192, #195, #199, #200, #207, #211, #212, #219, #222, #224, #230, #231, #232, #233, #234, #235 # 2014-07-02 version 0.5.9: * Support std::tr1 unordered containers by default (#51, #63, #68, #69) * Remove some warnings (#56) * Fix segmentation fault after malloc failures (#58, #59) * Fix alloc/dealloc mismatch (#52, #61) * Fix sample codes (#60, #64) * Support implicit conversion from integer to float/double (#54) * Improve documents (#45, #75, #82, #83) * Support CMake (#20, #87) * Remove Ruby dependencies in bootstrap (#86, #87) * Add FILE* buffer (#40) * Other bug fixes and refactoring: #39, #73, #77, #79, #80, #81, #84, #90 # 2013-12-23 version 0.5.8: * Move to the new github repository msgpack/msgpack-c * Support the new deserialization specification * fixes the problem of unpack helpers for array and map with 32bit compilers (#37, #38) * Other bug fixes and refactoring: #46, #41, #36, #35, #33, #32, #30, #29, #28, #27, #26, #25, #8, #3 * Update of documents: #23, #18, #17 # 2011-08-08 version 0.5.7: * fixes compile error problem with llvm-gcc and Mac OS X Lion # 2011-04-24 version 0.5.6: * #42 fixes double-free problem on msgpack_unpacker_release_zone # 2011-02-24 version 0.5.5: * eliminates dependency of winsock2.h header * fixes msgpack_vc.postbuild.bat file * fixes some implicit cast warnings # 2010-08-29 version 0.5.4: * includes msgpack_vc2008.vcproj file in source package * fixes type::fix_int types # 2010-08-27 version 0.5.3: * adds type::fix_{u,}int{8,16,32,64} types * adds msgpack_pack_fix_{u,}int{8,16,32,64} functions * adds packer::pack_fix_{u,}int{8,16,32,64} functions * fixes include paths # 2010-07-14 version 0.5.2: * type::raw::str(), operator==, operator!=, operator< and operator> are now const * generates version.h using AC_OUTPUT macro in ./configure # 2010-07-06 version 0.5.1: * Add msgpack_vrefbuffer_new and msgpack_vrefbuffer_free * Add msgpack_sbuffer_new and msgpack_sbuffer_free * Add msgpack_unpacker_next and msgpack_unpack_next * msgpack::unpack returns void * Add MSGPACK_VERSION{,_MAJOR,_MINOR} macros to check header version * Add msgpack_version{,_major,_minor} functions to check library version * ./configure supports --disable-cxx option not to build C++ API # 2010-04-29 version 0.5.0: * msgpack_object_type is changed. MSGPACK_OBJECT_NIL is now 0x00. * New safe streaming deserializer API. * Add object::object(const T&) and object::operator=(const T&) * Add operator==(object, const T&) * MSGPACK_DEFINE macro defines msgpack_object(object* obj, zone* z) * C++ programs doesn't need to link "msgpackc" library. msgpack-c-6.0.1/NEWS0000644000175000017460000000000014602712313013054 0ustar kondowheelmsgpack-c-6.0.1/COPYING0000644000175000017460000000031014602664031013417 0ustar kondowheelCopyright (C) 2008-2015 FURUHASHI Sadayuki Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) msgpack-c-6.0.1/README0000644000175000017460000000767314602712313013264 0ustar kondowheel`msgpack` for C =================== Version 6.0.1 [![Build Status](https://github.com/msgpack/msgpack-c/workflows/CI/badge.svg?branch=c_master)](https://github.com/msgpack/msgpack-c/actions) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/c_master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/c_master) [![codecov](https://codecov.io/gh/msgpack/msgpack-c/branch/c_master/graph/badge.svg)](https://codecov.io/gh/msgpack/msgpack-c/branch/c_master) It's like JSON but smaller and faster. Overview -------- [MessagePack](http://msgpack.org/) is an efficient binary serialization format, which lets you exchange data among multiple languages like JSON, except that it's faster and smaller. Small integers are encoded into a single byte and short strings require only one extra byte in addition to the strings themselves. Example ------- ```c #include #include int main(void) { /* msgpack::sbuffer is a simple buffer implementation. */ msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); /* serialize values into the buffer using msgpack_sbuffer_write callback function. */ msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* deserialize the buffer into msgpack_object instance. */ /* deserialized object is valid during the msgpack_zone instance alive. */ msgpack_zone mempool; msgpack_zone_init(&mempool, 2048); msgpack_object deserialized; msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); /* print the deserialized object. */ msgpack_object_print(stdout, deserialized); puts(""); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); return 0; } ``` See [`QUICKSTART-C.md`](./QUICKSTART-C.md) for more details. Usage ----- ### Building and Installing #### Install from git repository ##### Using the Terminal (CLI) You will need: - `gcc >= 4.1.0` - `cmake >= 2.8.0` How to build: $ git clone https://github.com/msgpack/msgpack-c.git $ cd msgpack-c $ git checkout c_master $ cmake . $ make $ sudo make install How to run tests: In order to run tests you must have the [GoogleTest](https://github.com/google/googletest) framework installed. If you do not currently have it, install it and re-run `cmake`. Then: $ make test When you use the C part of `msgpack-c`, you need to build and link the library. By default, both static/shared libraries are built. If you want to build only static library, set `BUILD_SHARED_LIBS=OFF` to cmake. If you want to build only shared library, set `BUILD_SHARED_LIBS=ON`. #### GUI on Windows Clone msgpack-c git repository. $ git clone https://github.com/msgpack/msgpack-c.git or using GUI git client. e.g.) tortoise git https://code.google.com/p/tortoisegit/ 1. Checkout to c_master branch 2. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html). 3. Set 'Where is the source code:' text box and 'Where to build the binaries:' text box. 4. Click 'Configure' button. 5. Choose your Visual Studio version. 6. Click 'Generate' button. 7. Open the created msgpack.sln on Visual Studio. 8. Build all. ### Documentation You can get additional information including the tutorial on the [wiki](https://github.com/msgpack/msgpack-c/wiki). Contributing ------------ `msgpack-c` is developed on GitHub at [msgpack/msgpack-c](https://github.com/msgpack/msgpack-c). To report an issue or send a pull request, use the [issue tracker](https://github.com/msgpack/msgpack-c/issues). Here's the list of [great contributors](https://github.com/msgpack/msgpack-c/graphs/contributors). License ------- `msgpack-c` is licensed under the Boost Software License, Version 1.0. See the [`LICENSE_1_0.txt`](./LICENSE_1_0.txt) file for details. msgpack-c-6.0.1/msgpack-c-config.cmake.in0000644000175000017460000000046514602664031017116 0ustar kondowheel#.rst: # msgpack # ------- # # The following import targets are created # # :: # # msgpack-c # msgpack-c-static (optional) # @PACKAGE_INIT@ include(CMakeFindDependencyMacro) if(NOT TARGET msgpack-c AND NOT TARGET msgpack-c-static) include("${CMAKE_CURRENT_LIST_DIR}/msgpack-c-targets.cmake") endif()