diff --git a/iguana/struct_pb.hpp b/iguana/struct_pb.hpp index 22cf4382..1ca54b62 100644 --- a/iguana/struct_pb.hpp +++ b/iguana/struct_pb.hpp @@ -346,7 +346,7 @@ inline std::string encode_pair_value(T& val, uint32_t field_no) { std::string temp; to_pb_impl(val, field_no, temp); if (temp.empty()) { - encode_key(field_no, WireType::LengthDelimeted, temp); + encode_key(field_no, get_wire_type(), temp); serialize_varint(0, temp); } return temp; diff --git a/test/test.cpp b/test/test.cpp index 65421d4e..7ac5f983 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -457,6 +457,25 @@ TEST_CASE("test struct_pb") { iguana::from_pb(st2, str); CHECK(st1.z == st2.z); } + { + message_t m{.id = 1, .t = {3, 4}}; + test_pb_st11 st1{1, {m}, {}}; + std::string str; + iguana::to_pb(st1, str); + + test_pb_st11 st2; + iguana::from_pb(st2, str); + CHECK(st1.z == st2.z); + } + { + message_t st1{}; + std::string str; + iguana::to_pb(st1, str); + + message_t st2{}; + iguana::from_pb(st2, str); + CHECK(st1.id == st2.id); + } { test_pb_st11 st1{1, {{{5, {7, 8}}}, {{9, {11, 12}}}}, {"test"}}; std::string str; @@ -476,6 +495,16 @@ TEST_CASE("test struct_pb") { iguana::from_pb(st2, str); CHECK(st1.z == st2.z); } + { + // map messages + test_pb_st12 st1{1, {{1, ""}, {0, "ok"}}, {{"", 4}, {"ok", 0}}}; + std::string str; + iguana::to_pb(st1, str); + + test_pb_st12 st2; + iguana::from_pb(st2, str); + CHECK(st1.z == st2.z); + } { // map messages test_pb_st13 st1;