From db531191789f48a141c42fef229bca7a7922443d Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 3 Oct 2024 12:35:44 +0200 Subject: cache get command (#183) * move TryParseObjectId and TryParseIoHash to Oid::TryParse and IoHash::TryParse respectively * zen cache-get command --- src/zencore/iohash.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/zencore/iohash.cpp') diff --git a/src/zencore/iohash.cpp b/src/zencore/iohash.cpp index 8f3f8da26..7200e6e3f 100644 --- a/src/zencore/iohash.cpp +++ b/src/zencore/iohash.cpp @@ -99,6 +99,24 @@ IoHash::FromHexString(std::string_view string) return io; } +bool +IoHash::TryParse(std::string_view Str, IoHash& Hash) +{ + using namespace std::literals; + + if (Str.size() == IoHash::StringLength) + { + return ParseHexBytes(Str.data(), Str.size(), Hash.Hash); + } + + if (Str.starts_with("0x"sv)) + { + return TryParse(Str.substr(2), Hash); + } + + return false; +} + const char* IoHash::ToHexString(char* outString /* 40 characters + NUL terminator */) const { -- cgit v1.2.3