diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-11-02 07:05:11 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-11-02 07:05:11 -0700 |
| commit | 4e88c80a22b6ca982341413ee806ade0df57b4b7 (patch) | |
| tree | 82c2daaac597f74595bc83c18646280a56898e1a /osdep | |
| parent | a6203ed0389c1b995ebe94935b2d1ddeb01f36ee (diff) | |
| download | infinitytier-4e88c80a22b6ca982341413ee806ade0df57b4b7.tar.gz infinitytier-4e88c80a22b6ca982341413ee806ade0df57b4b7.zip | |
RethinkDB native connector work, minor fixes.
Diffstat (limited to 'osdep')
| -rw-r--r-- | osdep/OSUtils.cpp | 15 | ||||
| -rw-r--r-- | osdep/OSUtils.hpp | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 0257458a..3325c621 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -451,6 +451,21 @@ uint64_t OSUtils::jsonInt(const nlohmann::json &jv,const uint64_t dfl) return dfl; } +uint64_t OSUtils::jsonIntHex(const nlohmann::json &jv,const uint64_t dfl) +{ + try { + if (jv.is_number()) { + return (uint64_t)jv; + } else if (jv.is_string()) { + std::string s = jv; + return Utils::hexStrToU64(s.c_str()); + } else if (jv.is_boolean()) { + return ((bool)jv ? 1ULL : 0ULL); + } + } catch ( ... ) {} + return dfl; +} + bool OSUtils::jsonBool(const nlohmann::json &jv,const bool dfl) { try { diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp index 45770b7f..fd1b31d9 100644 --- a/osdep/OSUtils.hpp +++ b/osdep/OSUtils.hpp @@ -278,6 +278,7 @@ public: static nlohmann::json jsonParse(const std::string &buf); static std::string jsonDump(const nlohmann::json &j,int indentation = 1); static uint64_t jsonInt(const nlohmann::json &jv,const uint64_t dfl); + static uint64_t jsonIntHex(const nlohmann::json &jv,const uint64_t dfl); static bool jsonBool(const nlohmann::json &jv,const bool dfl); static std::string jsonString(const nlohmann::json &jv,const char *dfl); static std::string jsonBinFromHex(const nlohmann::json &jv); |
