Skip to content
Snippets Groups Projects
Commit a06f3970 authored by Michael Davis's avatar Michael Davis
Browse files

[checksum] Improves performance of ChecksumBlob::length()

It isn't necessary to serialize the protobuf to compute the serialized
length, use ByteSizeLong() instead.
parent 9e9be445
No related branches found
No related tags found
No related merge requests found
......@@ -98,8 +98,9 @@ std::string ChecksumBlob::serialize() const {
}
size_t ChecksumBlob::length() const {
// Inefficient as it requires re-doing the serialization. Check if we really need this method.
return serialize().length();
common::ChecksumBlob p_csb;
ChecksumBlobToProtobuf(*this, p_csb);
return p_csb.ByteSizeLong();
}
void ChecksumBlob::deserialize(const std::string &bytearray) {
......
......@@ -160,7 +160,9 @@ TEST_F(cta_ChecksumBlobTest, serialize_deserialize) {
checksumBlob1.insert(MD5, "1234567890123456"); // 128 bits
checksumBlob1.insert(SHA1, "12345678901234567890"); // 160 bits
auto len = checksumBlob1.length();
auto bytearray = checksumBlob1.serialize();
ASSERT_EQ(len,bytearray.length());
ChecksumBlob checksumBlob2;
checksumBlob2.deserialize(bytearray);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment