mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 12:12:15 +02:00
jsonhelper : added json::format_compact() methods for formatting JSON into a compact representation without extraneous whitespace.
This commit is contained in:
parent
ff804f93f0
commit
760ae4a5f1
@ -27,6 +27,8 @@
|
|||||||
#include <openvpn/common/exception.hpp>
|
#include <openvpn/common/exception.hpp>
|
||||||
#include <openvpn/common/string.hpp>
|
#include <openvpn/common/string.hpp>
|
||||||
#include <openvpn/common/file.hpp>
|
#include <openvpn/common/file.hpp>
|
||||||
|
#include <openvpn/buffer/bufstr.hpp>
|
||||||
|
#include <openvpn/buffer/bufstream.hpp>
|
||||||
|
|
||||||
namespace openvpn {
|
namespace openvpn {
|
||||||
|
|
||||||
@ -297,6 +299,22 @@ namespace openvpn {
|
|||||||
return get_dict(root, name, optional, "");
|
return get_dict(root, name, optional, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void format_compact(const Json::Value& root, Buffer& buf)
|
||||||
|
{
|
||||||
|
Json::StreamWriterBuilder json_builder;
|
||||||
|
json_builder.settings_["indentation"] = "";
|
||||||
|
BufferStreamOut os(buf);
|
||||||
|
std::unique_ptr<Json::StreamWriter> sw(json_builder.newStreamWriter());
|
||||||
|
sw->write(root, &os);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format_compact(const Json::Value& root, const size_t size_hint=256)
|
||||||
|
{
|
||||||
|
BufferPtr bp = new BufferAllocated(size_hint, BufferAllocated::GROW);
|
||||||
|
format_compact(root, *bp);
|
||||||
|
return buf_to_string(*bp);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string fmt_name(const std::string& name, const std::string& title)
|
static std::string fmt_name(const std::string& name, const std::string& title)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user