Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Apr 12, 2024
1 parent 07d6118 commit 9ea0a3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iguana/struct_pb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ inline std::string encode_pair_value(T& val, uint32_t field_no) {
std::string temp;
to_pb_impl<value_type>(val, field_no, temp);
if (temp.empty()) {
encode_key(field_no, WireType::LengthDelimeted, temp);
encode_key(field_no, get_wire_type<value_type>(), temp);
serialize_varint(0, temp);
}
return temp;
Expand Down
29 changes: 29 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9ea0a3e

Please sign in to comment.