aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream
diff options
context:
space:
mode:
authorpkalinnikov <pkalinnikov@yandex-team.ru>2022-02-10 16:50:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:15 +0300
commit9e33e026829d561d6fd46d72b88c367952e08075 (patch)
tree2af190fca83ac522e9a7e29de1daae32582064b4 /util/stream
parentba5325cc01aabb81effc91ff1bdbb461313cbd00 (diff)
downloadydb-9e33e026829d561d6fd46d72b88c367952e08075.tar.gz
Restoring authorship annotation for <pkalinnikov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream')
-rw-r--r--util/stream/hex.cpp52
-rw-r--r--util/stream/hex.h10
-rw-r--r--util/stream/hex_ut.cpp34
3 files changed, 48 insertions, 48 deletions
diff --git a/util/stream/hex.cpp b/util/stream/hex.cpp
index 1c05330504..6d91cbe1cf 100644
--- a/util/stream/hex.cpp
+++ b/util/stream/hex.cpp
@@ -1,30 +1,30 @@
-#include "hex.h"
-
+#include "hex.h"
+
#include "output.h"
-#include <util/string/hex.h>
-
+#include <util/string/hex.h>
+
void HexEncode(const void* in, size_t len, IOutputStream& out) {
- static const size_t NUM_OF_BYTES = 32;
- char buffer[NUM_OF_BYTES * 2];
-
- auto current = static_cast<const char*>(in);
- for (size_t take = 0; len; current += take, len -= take) {
- take = Min(NUM_OF_BYTES, len);
- HexEncode(current, take, buffer);
- out.Write(buffer, take * 2);
- }
-}
-
+ static const size_t NUM_OF_BYTES = 32;
+ char buffer[NUM_OF_BYTES * 2];
+
+ auto current = static_cast<const char*>(in);
+ for (size_t take = 0; len; current += take, len -= take) {
+ take = Min(NUM_OF_BYTES, len);
+ HexEncode(current, take, buffer);
+ out.Write(buffer, take * 2);
+ }
+}
+
void HexDecode(const void* in, size_t len, IOutputStream& out) {
Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode"));
-
- static const size_t NUM_OF_BYTES = 32;
- char buffer[NUM_OF_BYTES];
-
- auto current = static_cast<const char*>(in);
- for (size_t take = 0; len; current += take, len -= take) {
- take = Min(NUM_OF_BYTES * 2, len);
- HexDecode(current, take, buffer);
- out.Write(buffer, take / 2);
- }
-}
+
+ static const size_t NUM_OF_BYTES = 32;
+ char buffer[NUM_OF_BYTES];
+
+ auto current = static_cast<const char*>(in);
+ for (size_t take = 0; len; current += take, len -= take) {
+ take = Min(NUM_OF_BYTES * 2, len);
+ HexDecode(current, take, buffer);
+ out.Write(buffer, take / 2);
+ }
+}
diff --git a/util/stream/hex.h b/util/stream/hex.h
index a018933b1b..68451d781f 100644
--- a/util/stream/hex.h
+++ b/util/stream/hex.h
@@ -1,8 +1,8 @@
-#pragma once
-
-#include <util/system/types.h>
-
+#pragma once
+
+#include <util/system/types.h>
+
class IOutputStream;
-
+
void HexEncode(const void* in, size_t len, IOutputStream& out);
void HexDecode(const void* in, size_t len, IOutputStream& out);
diff --git a/util/stream/hex_ut.cpp b/util/stream/hex_ut.cpp
index 5074a0b616..1a6bf5a6d3 100644
--- a/util/stream/hex_ut.cpp
+++ b/util/stream/hex_ut.cpp
@@ -1,29 +1,29 @@
-#include "hex.h"
-
+#include "hex.h"
+
#include <library/cpp/testing/unittest/registar.h>
#include "str.h"
-
+
Y_UNIT_TEST_SUITE(THexCodingTest) {
void TestImpl(const TString& data) {
TString encoded;
- TStringOutput encodedOut(encoded);
+ TStringOutput encodedOut(encoded);
HexEncode(data.data(), data.size(), encodedOut);
-
+
UNIT_ASSERT_EQUAL(encoded.size(), data.size() * 2);
-
+
TString decoded;
- TStringOutput decodedOut(decoded);
+ TStringOutput decodedOut(decoded);
HexDecode(encoded.data(), encoded.size(), decodedOut);
-
- UNIT_ASSERT_EQUAL(decoded, data);
- }
-
+
+ UNIT_ASSERT_EQUAL(decoded, data);
+ }
+
Y_UNIT_TEST(TestEncodeDecodeToStream) {
TString data = "100ABAcaba500,$%0987123456 \n\t\x01\x02\x03.";
- TestImpl(data);
- }
-
+ TestImpl(data);
+ }
+
Y_UNIT_TEST(TestEmpty) {
- TestImpl("");
- }
-}
+ TestImpl("");
+ }
+}