Mercurial > hg > orthanc
diff OrthancFramework/Sources/Toolbox.cpp @ 4392:3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Dec 2020 18:09:47 +0100 |
parents | 785a2713323e |
children | e8e95b80194f |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Toolbox.cpp Mon Dec 21 08:47:29 2020 +0100 +++ b/OrthancFramework/Sources/Toolbox.cpp Mon Dec 21 18:09:47 2020 +0100 @@ -27,6 +27,8 @@ #include "OrthancException.h" #include "Logging.h" +#include <json/json.h> + #include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/replace.hpp> #include <boost/lexical_cast.hpp> @@ -2269,6 +2271,41 @@ } } } + + + bool Toolbox::ReadJson(Json::Value& target, + const std::string& source) + { + Json::Reader reader; + return reader.parse(source, target); + } + + + bool Toolbox::ReadJson(Json::Value& target, + const void* buffer, + size_t size) + { + Json::Reader reader; + return reader.parse(reinterpret_cast<const char*>(buffer), + reinterpret_cast<const char*>(buffer) + size, target); + } + + + void Toolbox::WriteJson(std::string& target, + const Json::Value& source, + bool fast) + { + if (fast) + { + Json::FastWriter writer; + target = writer.write(source); + } + else + { + Json::StyledWriter writer; + target = writer.write(source); + } + } }