Update Json.
This commit is contained in:
parent
0a27c6d6af
commit
11da7a3155
10 changed files with 179 additions and 87 deletions
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,6 +23,7 @@
|
|||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -119,6 +114,21 @@ const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const
|
|||
}
|
||||
|
||||
|
||||
double xmrig::Json::getDouble(const rapidjson::Value &obj, const char *key, double defaultValue)
|
||||
{
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && (i->value.IsDouble() || i->value.IsLosslessDouble())) {
|
||||
return i->value.GetDouble();
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue)
|
||||
{
|
||||
if (isEmpty(obj)) {
|
||||
|
@ -149,6 +159,25 @@ int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int6
|
|||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Json::getString(const rapidjson::Value &obj, const char *key, size_t maxSize)
|
||||
{
|
||||
if (isEmpty(obj)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i == obj.MemberEnd() || !i->value.IsString()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (maxSize == 0 || i->value.GetStringLength() <= maxSize) {
|
||||
return i->value.GetString();
|
||||
}
|
||||
|
||||
return { i->value.GetString(), maxSize };
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue)
|
||||
{
|
||||
if (isEmpty(obj)) {
|
||||
|
@ -222,6 +251,11 @@ bool xmrig::Json::convertOffset(std::istream &ifs, size_t offset, size_t &line,
|
|||
}
|
||||
|
||||
|
||||
xmrig::JsonReader::JsonReader() :
|
||||
m_obj(kNullValue)
|
||||
{}
|
||||
|
||||
|
||||
bool xmrig::JsonReader::isEmpty() const
|
||||
{
|
||||
return Json::isEmpty(m_obj);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue