diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-01-31 21:13:19 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-01-31 21:13:19 +0100 |
commit | c63b1a4591a0a54d3ccd449573f408739ea29af2 (patch) | |
tree | 2527ffb477e8b4395ede48383402d77ecd4e2b5b /src/storage.cpp | |
parent | fc368248316aebeb756bdd8b85d3f819eddc49d1 (diff) |
Storage: hexadecimal encoding of binary record items
Diffstat (limited to 'src/storage.cpp')
-rw-r--r-- | src/storage.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/storage.cpp b/src/storage.cpp index 6e2f118..4cfa08d 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1,5 +1,4 @@ #include "storage.h" -#include "base64.h" #include <charconv> #include <chrono> @@ -1018,9 +1017,17 @@ optional<RecordT<S>> RecordT<S>::decode(const S & st, } else if (type == "t") items->emplace_back(name, value); - else if (type == "b") - items->emplace_back(name, base64::decode(value)); - else if (type == "d") + else if (type == "b") { + if (value.size() % 2) + return nullopt; + vector<uint8_t> binary(value.size() / 2, 0); + + for (size_t i = 0; i < binary.size(); i++) + std::from_chars(value.data() + 2 * i, + value.data() + 2 * i + 2, + binary[i], 16); + items->emplace_back(name, std::move(binary)); + } else if (type == "d") items->emplace_back(name, ZonedTime(value)); else if (type == "u") items->emplace_back(name, UUID(value)); @@ -1100,7 +1107,11 @@ vector<uint8_t> RecordT<S>::encodeInner() const value = *x; } else if (auto x = item.asBinary()) { type = "b"; - value = base64::encode(*x); + value.resize(x->size() * 2, '0'); + for (size_t i = 0; i < x->size(); i++) + std::to_chars(value.data() + 2 * i + ((*x)[i] < 0x10), + value.data() + 2 * i + 2, + (*x)[i], 16); } else if (auto x = item.asDate()) { type = "d"; value = string(*x); |