diff options
author | Kennan Gumbs <kennangumbs@google.com> | 2021-07-07 15:54:14 -0400 |
---|---|---|
committer | Openscreen LUCI CQ <openscreen-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2021-07-14 01:16:32 +0000 |
commit | 7e167e2bc4c8c0c650f00b995e1e20cb1ae1f479 (patch) | |
tree | 6a84d39db2234179deaac624ec05e0d86c40ceb1 /util | |
parent | 01c7cc260a28bc0a814249f41825b35e021be271 (diff) | |
download | openscreen-7e167e2bc4c8c0c650f00b995e1e20cb1ae1f479.tar.gz |
Remove abseil dependency from HexEncode method
Currently the HexEncode method defined in util/stringprintf.h depends on
absl::Span, which is part of abseil. This patch removes the dependency,
allowing the method to be more widely used.
Bug: b/158660166
Change-Id: I37715271391000b5c61d5a657f604db2bc6c882e
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/3001949
Reviewed-by: Jordan Bayles <jophba@chromium.org>
Commit-Queue: Jordan Bayles <jophba@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/stringprintf.cc | 6 | ||||
-rw-r--r-- | util/stringprintf.h | 2 | ||||
-rw-r--r-- | util/stringprintf_unittest.cc | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/util/stringprintf.cc b/util/stringprintf.cc index 2d9bba22..49c29dc8 100644 --- a/util/stringprintf.cc +++ b/util/stringprintf.cc @@ -32,11 +32,11 @@ std::string StringPrintf(const char* format, ...) { return result; } -std::string HexEncode(absl::Span<const uint8_t> bytes) { +std::string HexEncode(const uint8_t* bytes, std::size_t len) { std::ostringstream hex_dump; hex_dump << std::setfill('0') << std::hex; - for (const uint8_t byte : bytes) { - hex_dump << std::setw(2) << static_cast<int>(byte); + for (std::size_t i = 0; i < len; i++) { + hex_dump << std::setw(2) << static_cast<int>(bytes[i]); } return hex_dump.str(); } diff --git a/util/stringprintf.h b/util/stringprintf.h index 0e7984e1..7e54be3c 100644 --- a/util/stringprintf.h +++ b/util/stringprintf.h @@ -55,7 +55,7 @@ void PrettyPrintAsciiHex(std::ostream& os, It first, It last) { } // Returns a hex string representation of the given |bytes|. -std::string HexEncode(absl::Span<const uint8_t> bytes); +std::string HexEncode(const uint8_t* bytes, std::size_t len); } // namespace openscreen diff --git a/util/stringprintf_unittest.cc b/util/stringprintf_unittest.cc index e37e7cb6..bf882163 100644 --- a/util/stringprintf_unittest.cc +++ b/util/stringprintf_unittest.cc @@ -20,13 +20,13 @@ TEST(StringPrintf, ProducesFormattedStrings) { TEST(HexEncode, ProducesEmptyStringFromEmptyByteArray) { const uint8_t kSomeMemoryLocation = 0; - EXPECT_EQ("", HexEncode(absl::Span<const uint8_t>(&kSomeMemoryLocation, 0))); + EXPECT_EQ("", HexEncode(&kSomeMemoryLocation, 0)); } TEST(HexEncode, ProducesHexStringsFromBytes) { const uint8_t kMessage[] = "Hello world!"; const char kMessageInHex[] = "48656c6c6f20776f726c642100"; - EXPECT_EQ(kMessageInHex, HexEncode(kMessage)); + EXPECT_EQ(kMessageInHex, HexEncode(kMessage, sizeof(kMessage))); } } // namespace |