mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 15:34:08 +02:00
parent
a133c1d393
commit
ec239933db
@ -61,6 +61,7 @@ struct define_map<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
|
@ -62,6 +62,7 @@ struct define_map<A0, A1> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -114,6 +115,7 @@ struct define_map<A0, A1, A2, A3> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -180,6 +182,7 @@ struct define_map<A0, A1, A2, A3, A4, A5> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -260,6 +263,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -354,6 +358,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -462,6 +467,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -584,6 +590,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13> {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -720,6 +727,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -870,6 +878,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -1034,6 +1043,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -1212,6 +1222,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -1404,6 +1415,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -1610,6 +1622,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -1830,6 +1843,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -2064,6 +2078,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
@ -2312,6 +2327,7 @@ struct define_map<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A1
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.insert(
|
||||
std::map<std::string, msgpack::object const*>::value_type(
|
||||
std::string(
|
||||
|
@ -72,6 +72,7 @@ struct define_map {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
std::map<std::string, msgpack::object const*> kvmap;
|
||||
for (uint32_t i = 0; i < o.via.map.size; ++i) {
|
||||
if (o.via.map.ptr[i].key.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
kvmap.emplace(
|
||||
std::string(
|
||||
o.via.map.ptr[i].key.via.str.ptr,
|
||||
|
@ -601,3 +601,28 @@ TEST(MSGPACK_NVP, combination)
|
||||
EXPECT_EQ(d2.c, 3);
|
||||
EXPECT_EQ(d2.d, "ABC");
|
||||
}
|
||||
|
||||
struct invalid_key {
|
||||
int val;
|
||||
MSGPACK_DEFINE_MAP(val);
|
||||
};
|
||||
|
||||
TEST(MSGPACK_USER_DEFINED, test_invalid_key_type)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::packer<msgpack::sbuffer> pk(sbuf);
|
||||
pk.pack_map(1);
|
||||
pk.pack_int(42);
|
||||
pk.pack_int(43);
|
||||
msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
try {
|
||||
oh.get().as<invalid_key>();
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user