From 7aba9b0cbb0f60907562c8b1c5f9e35e7ef29842 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Wed, 9 Dec 2015 12:39:56 +0100 Subject: [PATCH] Add some velocy helpers, to be deleted later. --- lib/Basics/JsonHelper.h | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/Basics/JsonHelper.h b/lib/Basics/JsonHelper.h index b4866fe1ee..6cecd622a0 100644 --- a/lib/Basics/JsonHelper.h +++ b/lib/Basics/JsonHelper.h @@ -35,6 +35,9 @@ #include "Basics/json.h" #include "Basics/StringBuffer.h" +#include "velocypack/Parser.h" +#include "velocypack/Builder.h" + namespace triagens { namespace basics { @@ -280,6 +283,45 @@ namespace triagens { static TRI_json_t const* checkAndGetArrayValue (TRI_json_t const*, char const*); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief TRI_json_t to VelocyPack, this is a temporary, inefficient method +/// which must be removed later on. +//////////////////////////////////////////////////////////////////////////////// + + static std::shared_ptr toVelocyPack ( + TRI_json_t const* json) { + std::string tmp = toString(json); + arangodb::velocypack::Parser parser; + try { + parser.parse(tmp); + } + catch (...) { + return std::shared_ptr(); + } + return parser.steal(); + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief TRI_json_t to VelocyPack, writing into an existing Builder +//////////////////////////////////////////////////////////////////////////////// + + static int toVelocyPack ( + TRI_json_t const* json, + arangodb::velocypack::Builder& builder) { + std::string tmp = toString(json); + arangodb::velocypack::Options opt; + opt.clearBuilderBeforeParse = false; + arangodb::velocypack::Parser parser(builder, &opt); + try { + parser.parse(tmp); + } + catch (...) { + return TRI_ERROR_INTERNAL; + } + return TRI_ERROR_NO_ERROR; + } + }; //////////////////////////////////////////////////////////////////////////////// @@ -1149,7 +1191,6 @@ namespace triagens { } } - // ----------------------------------------------------------------------------- // --SECTION-- private variables // -----------------------------------------------------------------------------