c++ - Msgpack packing bools bug -
for c++ project use c++ msgpack library available in ubuntu (14.04) standard repository under name libmsgpack-dev.
all works fine except when try pack bools. there things go absolutely bananas. first wrote simple test study pack
method. turned out, can not trusted packing bools. here simple test showing problem:
#include <msgpack.hpp> test_case("bool packing", "[msgpack1]") { msgpack::sbuffer buf; msgpack::packer<msgpack::sbuffer> p(&buf); std::string key = "boolvalue"; bool value = true; p.pack_map(1); { p.pack(key); p.pack(value); } msgpack::unpacked msg; msgpack::unpack(&msg, buf.data(), buf.size()); std::map<std::string, msgpack::object> m; msg.get().convert(&m); bool loaded_value; m.at(key).convert(&loaded_value); info("we packed: " << value); info("we loaded: " << loaded_value); require(value == loaded_value); }
with result:
unit_tests/unit_msgpack.cpp:30: failed: require( value == loaded_value ) expansion: true == false messages: packed: 1 loaded: 0
i thought ok, there way around? yes, discovered methods pack_true
, pack_false
. right, packing bools need call these 2 functions explicitly , work fine. no. test:
test_case("bool packing 2 elements", "[msgpack2]") { msgpack::sbuffer buf; msgpack::packer<msgpack::sbuffer> p(&buf); std::string key1 = "boolvalue1"; std::string key2 = "boolvalue2"; bool value1 = false; bool value2 = true; p.pack_map(2); { p.pack(key1); if (value1) { p.pack_true(); } else { p.pack_false(); } p.pack(key2); if (value2) { p.pack_true(); } else { p.pack_false(); } } msgpack::unpacked msg; msgpack::unpack(&msg, buf.data(), buf.size()); std::map<std::string, msgpack::object> m; msg.get().convert(&m); bool loaded_value1; bool loaded_value2; m.at(key1).convert(&loaded_value1); m.at(key2).convert(&loaded_value2); info("we packed: " << value1 << " : " << value2); info("we loaded: " << loaded_value1 << " : " << loaded_value2); require((value1 == loaded_value1 && value2 == loaded_value2)); }
i got following result:
unit_tests/unit_msgpack.cpp:72: failed: require( (value1 == loaded_value1 && value2 == loaded_value2) ) expansion: false messages: packed: 0 : 1 loaded: 0 : 0
can please me out of this? there bug in library or doing wrong?
i don't know problem solved removing packages libmsgpackc2
, libmsgpack3
, installing msgpack git repository. described. code has compiled -i msgpack-c/include
flag.
i guess msgpack package in ubuntu repository old , deprecated.
Comments
Post a Comment