Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class MessageUtil {

/**
* Convert from google.protobuf.Any to bytes as std::string
* @param message source google.protobuf.Any message.
* @param any source google.protobuf.Any message.
*
* @return std::string consists of bytes in the input message.
*/
Expand Down
23 changes: 23 additions & 0 deletions test/common/protobuf/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,29 @@ TEST_F(ProtobufUtilityTest, HashedValueStdHash) {
EXPECT_NE(set.find(hv3), set.end());
}

TEST_F(ProtobufUtilityTest, AnyBytes) {
{
ProtobufWkt::StringValue source;
source.set_value("abc");
ProtobufWkt::Any source_any;
source_any.PackFrom(source);
EXPECT_EQ(MessageUtil::anyToBytes(source_any), "abc");
}
{
ProtobufWkt::BytesValue source;
source.set_value({0x01, 0x02, 0x03});
ProtobufWkt::Any source_any;
source_any.PackFrom(source);
EXPECT_EQ(MessageUtil::anyToBytes(source_any), "\x01\x02\x03");
}
{
envoy::config::cluster::v3::Filter filter;
ProtobufWkt::Any source_any;
source_any.PackFrom(filter);
EXPECT_EQ(MessageUtil::anyToBytes(source_any), source_any.value());
}
}

// MessageUtility::anyConvert() with the wrong type throws.
TEST_F(ProtobufUtilityTest, AnyConvertWrongType) {
ProtobufWkt::Duration source_duration;
Expand Down