Skip to content

Commit

Permalink
fix(echo): support serializing nested messages (#670)
Browse files Browse the repository at this point in the history
* fix(echo): support serializing nested messages

* Apply suggestions from code review

Co-authored-by: Daan Timmer <8293597+daantimmer@users.noreply.github.com>

* Update protobuf/echo/ProtoMessageSender.hpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Daan Timmer <8293597+daantimmer@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent 751fefd commit 63c55e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion infra/util/BoundedString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ namespace infra
for (; additional != 0; --additional)
range[index++] = *first++;

return &range[index];
return std::next(range.begin(), index);
}

template<class T>
Expand Down
3 changes: 2 additions & 1 deletion protobuf/echo/ProtoMessageSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ namespace services
template<class Message>
bool ProtoMessageSenderBase::SerializeField(ProtoMessage<Message>, infra::ProtoFormatter& formatter, const Message& value, uint32_t fieldNumber, bool& retry) const
{
infra::DataOutputStream::WithWriter<infra::CountingStreamWriter> countingStream;
std::array<uint8_t, 16> saveStateStorage; // For writing length fields
infra::DataOutputStream::WithWriter<infra::CountingStreamWriter> countingStream{ saveStateStorage };
infra::ProtoFormatter countingFormatter{ countingStream };
value.Serialize(countingFormatter);
formatter.PutLengthDelimitedSize(countingStream.Writer().Processed(), fieldNumber);
Expand Down
5 changes: 5 additions & 0 deletions protobuf/echo/test/TestMessages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ message TestMoreNestedMessage
NestedMessage2 message2 = 2;
}

message TestDeepNestedMessage
{
TestNestedMessage message = 1;
}

message TestNestedRepeatedMessage
{
message NestedMessage
Expand Down
8 changes: 8 additions & 0 deletions protobuf/echo/test/TestProtoMessageSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ TEST_F(ProtoMessageSenderTest, format_more_nested_message)
ExpectFill({ (1 << 3) | 2, 2, 1 << 3, 5, (2 << 3) | 2, 2, 2 << 3, 10 }, sender);
}

TEST_F(ProtoMessageSenderTest, format_deep_nested_message)
{
test_messages::TestDeepNestedMessage message{ { 5 } };
services::ProtoMessageSender sender{ message };

ExpectFill({ 1 << 3 | 2, 4, 1 << 3 | 2, 2, 1 << 3, 5 }, sender);
}

TEST_F(ProtoMessageSenderTest, dont_format_on_buffer_full)
{
test_messages::TestBoolWithBytes message;
Expand Down

0 comments on commit 63c55e0

Please sign in to comment.