Skip to content
Merged
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
16 changes: 8 additions & 8 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ class RepeatedPtrUtil {
// Based on MessageUtil::hash() defined below.
template <class ProtoType>
static std::size_t hash(const Protobuf::RepeatedPtrField<ProtoType>& source) {
// Use Protobuf::io::CodedOutputStream to force deterministic serialization, so that the same
// message doesn't hash to different values.
std::string text;
{
// For memory safety, the StringOutputStream needs to be destroyed before
// we read the string.
Protobuf::io::StringOutputStream string_stream(&text);
Protobuf::io::CodedOutputStream coded_stream(&string_stream);
coded_stream.SetSerializationDeterministic(true);
Protobuf::TextFormat::Printer printer;
printer.SetExpandAny(true);
printer.SetUseFieldNumber(true);
printer.SetSingleLineMode(true);
printer.SetHideUnknownFields(true);
for (const auto& message : source) {
message.SerializeToCodedStream(&coded_stream);
std::string text_message;
printer.PrintToString(message, &text_message);
absl::StrAppend(&text, text_message);
}
}
return HashUtil::xxHash64(text);
Expand Down