Commit fc1dcc0f by Abseil Team Committed by Copybara-Service

Changes absl::crc32c_t insertion operator (<<) to return value as 0-padded hex instead of dec

PiperOrigin-RevId: 552927211
Change-Id: I0375d60a9df4cdfc694fe8d3b3d790f80fc614a1
parent 5b3b0ed8
...@@ -93,6 +93,7 @@ cc_library( ...@@ -93,6 +93,7 @@ cc_library(
"//absl/base:endian", "//absl/base:endian",
"//absl/base:prefetch", "//absl/base:prefetch",
"//absl/strings", "//absl/strings",
"//absl/strings:str_format",
], ],
) )
......
...@@ -77,6 +77,7 @@ absl_cc_library( ...@@ -77,6 +77,7 @@ absl_cc_library(
absl::dynamic_annotations absl::dynamic_annotations
absl::endian absl::endian
absl::prefetch absl::prefetch
absl::str_format
absl::strings absl::strings
) )
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <ostream> #include <ostream>
#include "absl/crc/internal/crc32c_inline.h" #include "absl/crc/internal/crc32c_inline.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
namespace absl { namespace absl {
...@@ -175,7 +176,7 @@ crc32c_t RemoveCrc32cSuffix(crc32c_t full_string_crc, crc32c_t suffix_crc, ...@@ -175,7 +176,7 @@ crc32c_t RemoveCrc32cSuffix(crc32c_t full_string_crc, crc32c_t suffix_crc,
// //
// Streams the CRC32C value `crc` to the stream `os`. // Streams the CRC32C value `crc` to the stream `os`.
inline std::ostream& operator<<(std::ostream& os, crc32c_t crc) { inline std::ostream& operator<<(std::ostream& os, crc32c_t crc) {
return os << static_cast<uint32_t>(crc); return os << absl::StreamFormat("%08x", static_cast<uint32_t>(crc));
} }
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <sstream>
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -191,4 +192,22 @@ TEST(CRC32C, RemoveSuffix) { ...@@ -191,4 +192,22 @@ TEST(CRC32C, RemoveSuffix) {
EXPECT_EQ(absl::RemoveCrc32cSuffix(crc_ab, crc_b, world.size()), crc_a); EXPECT_EQ(absl::RemoveCrc32cSuffix(crc_ab, crc_b, world.size()), crc_a);
} }
TEST(CRC32C, InsertionOperator) {
{
std::ostringstream buf;
buf << absl::crc32c_t{0xc99465aa};
EXPECT_EQ(buf.str(), "c99465aa");
}
{
std::ostringstream buf;
buf << absl::crc32c_t{0};
EXPECT_EQ(buf.str(), "00000000");
}
{
std::ostringstream buf;
buf << absl::crc32c_t{17};
EXPECT_EQ(buf.str(), "00000011");
}
}
} // namespace } // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment