No public description PiperOrigin-RevId: 588858270
diff --git a/centipede/blob_file.cc b/centipede/blob_file.cc index 5c2e38b..fd9bbc2 100644 --- a/centipede/blob_file.cc +++ b/centipede/blob_file.cc
@@ -15,7 +15,6 @@ #include "./centipede/blob_file.h" #include <cstddef> -#include <cstdint> #include <memory> #include <string_view> #include <vector> @@ -184,8 +183,7 @@ else return riegeli_reader_.status(); } - blob = ByteSpan(reinterpret_cast<const uint8_t *>(record.data()), - record.size()); + blob = AsByteSpan(record); return absl::OkStatus(); } @@ -241,10 +239,7 @@ } absl::Status Write(ByteSpan blob) override { - if (!writer_.WriteRecord(absl::string_view( - reinterpret_cast<const char *>(blob.data()), blob.size()))) { - return writer_.status(); - } + if (!writer_.WriteRecord(AsStringView(blob))) return writer_.status(); // Riegeli's automatic flushing happens in chunks, not on record boundaries. // Flushing explicitly after every write makes it visible to readers earlier // especially if writes are infrequent and/or the size of records is small
diff --git a/centipede/defs.h b/centipede/defs.h index 61eaeec..e06baca 100644 --- a/centipede/defs.h +++ b/centipede/defs.h
@@ -20,6 +20,7 @@ #include <cstddef> #include <cstdint> #include <random> +#include <string_view> #include <vector> #include "absl/types/span.h" @@ -32,6 +33,15 @@ using ByteArray = std::vector<uint8_t>; using ByteSpan = absl::Span<const uint8_t>; +inline ByteSpan AsByteSpan(std::string_view str) { + return ByteSpan(reinterpret_cast<const uint8_t *>(str.data()), str.size()); +} + +inline std::string_view AsStringView(ByteSpan str) { + return std::string_view(reinterpret_cast<const char *>(str.data()), + str.size()); +} + // Macro used to allow tests to access protected or private members of a class. #define FRIEND_TEST(test_case_name, test_name) \ friend class test_case_name##_##test_name##_Test
diff --git a/centipede/hash.cc b/centipede/hash.cc index 61ef118..14a4d19 100644 --- a/centipede/hash.cc +++ b/centipede/hash.cc
@@ -42,8 +42,7 @@ std::string Hash(std::string_view str) { static_assert(sizeof(decltype(str)::value_type) == sizeof(uint8_t)); - return Hash( - ByteSpan(reinterpret_cast<const uint8_t *>(str.data()), str.size())); + return Hash(AsByteSpan(str)); } } // namespace centipede