Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(echo): support serializing nested messages #670

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading