mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add Json::to_string:
This allows the declaration for FastWriter to be hidden and makes conversion of Json::Value objects to strings a little less clunky.
This commit is contained in:
committed by
Vinnie Falco
parent
8c1c2f5d05
commit
9cba944d21
@@ -2416,6 +2416,9 @@
|
||||
<ClCompile Include="..\..\src\ripple\json\impl\Tests.cpp">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\json\impl\to_string.cpp">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\json\JsonPropertyStream.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\json\json_config.h">
|
||||
@@ -2430,6 +2433,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\json\json_writer.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\json\to_string.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\net\HTTPClient.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\net\HTTPRequest.h">
|
||||
|
||||
@@ -3429,6 +3429,9 @@
|
||||
<ClCompile Include="..\..\src\ripple\json\impl\Tests.cpp">
|
||||
<Filter>ripple\json\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\json\impl\to_string.cpp">
|
||||
<Filter>ripple\json\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\json\JsonPropertyStream.h">
|
||||
<Filter>ripple\json</Filter>
|
||||
</ClInclude>
|
||||
@@ -3450,6 +3453,9 @@
|
||||
<ClInclude Include="..\..\src\ripple\json\json_writer.h">
|
||||
<Filter>ripple\json</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\json\to_string.h">
|
||||
<Filter>ripple\json</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\net\HTTPClient.h">
|
||||
<Filter>ripple\net</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -33,8 +33,7 @@ void BookListeners::removeSubscriber (std::uint64_t seq)
|
||||
|
||||
void BookListeners::publish (Json::Value const& jvObj)
|
||||
{
|
||||
Json::FastWriter jfwWriter;
|
||||
std::string sObj = jfwWriter.write (jvObj);
|
||||
std::string sObj = to_string (jvObj);
|
||||
|
||||
ScopedLockType sl (mLock);
|
||||
NetworkOPs::SubMapType::const_iterator it = mListeners.begin ();
|
||||
|
||||
@@ -1807,8 +1807,7 @@ void NetworkOPsImp::pubServer ()
|
||||
jvObj [jss::load_factor] =
|
||||
(mLastLoadFactor = getApp().getFeeTrack ().getLoadFactor ());
|
||||
|
||||
Json::FastWriter w;
|
||||
std::string sObj = w.write (jvObj);
|
||||
std::string sObj = to_string (jvObj);
|
||||
|
||||
|
||||
for (auto i = mSubServer.begin (); i != mSubServer.end (); )
|
||||
@@ -2701,8 +2700,7 @@ void NetworkOPsImp::pubValidatedTransaction (
|
||||
*alTx.getTxn (), alTx.getResult (), true, alAccepted);
|
||||
jvObj[jss::meta] = alTx.getMeta ()->getJson (0);
|
||||
|
||||
Json::FastWriter w;
|
||||
std::string sObj = w.write (jvObj);
|
||||
std::string sObj = to_string (jvObj);
|
||||
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
@@ -2814,8 +2812,7 @@ void NetworkOPsImp::pubAccountTransaction (
|
||||
if (alTx.isApplied ())
|
||||
jvObj[jss::meta] = alTx.getMeta ()->getJson (0);
|
||||
|
||||
Json::FastWriter w;
|
||||
std::string sObj = w.write (jvObj);
|
||||
std::string sObj = to_string (jvObj);
|
||||
|
||||
BOOST_FOREACH (InfoSub::ref isrListener, notify)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,6 @@ TER TransactionEngine::applyTransaction (
|
||||
{
|
||||
WriteLog (lsFATAL, TransactionEngine) <<
|
||||
"Transaction serdes mismatch";
|
||||
Json::StyledStreamWriter ssw;
|
||||
WriteLog (lsINFO, TransactionEngine) << txn.getJson (0);
|
||||
WriteLog (lsFATAL, TransactionEngine) << s2.getJson (0);
|
||||
assert (false);
|
||||
|
||||
@@ -138,11 +138,9 @@ public:
|
||||
|
||||
void send (connection_ptr cpClient, Json::Value const& jvObj, bool broadcast)
|
||||
{
|
||||
Json::FastWriter jfwWriter;
|
||||
|
||||
// WriteLog (lsDEBUG, WSServerHandlerLog) << "Ws:: Object '" << jfwWriter.write(jvObj) << "'";
|
||||
|
||||
send (cpClient, jfwWriter.write (jvObj), broadcast);
|
||||
send (cpClient, to_string (jvObj), broadcast);
|
||||
}
|
||||
|
||||
void pingTimer (connection_ptr cpClient)
|
||||
|
||||
@@ -966,9 +966,8 @@ public:
|
||||
if (parsedOK)
|
||||
{
|
||||
STParsedJSONObject parsed ("test", jsonObject);
|
||||
Json::FastWriter writer;
|
||||
std::string const& serialized (
|
||||
writer.write (parsed.object->getJson(0)));
|
||||
to_string (parsed.object->getJson(0)));
|
||||
expect (serialized == json, serialized + " should equal: " + json);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace Json
|
||||
{
|
||||
|
||||
|
||||
30
src/ripple/json/impl/to_string.cpp
Normal file
30
src/ripple/json/impl/to_string.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/json/json_writer.h>
|
||||
|
||||
namespace Json
|
||||
{
|
||||
|
||||
std::string to_string (Value const& value)
|
||||
{
|
||||
return FastWriter ().write (value);
|
||||
}
|
||||
|
||||
} // namespace Json
|
||||
36
src/ripple/json/to_string.h
Normal file
36
src/ripple/json/to_string.h
Normal file
@@ -0,0 +1,36 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef JSON_TO_STRING_H_INCLUDED
|
||||
#define JSON_TO_STRING_H_INCLUDED
|
||||
|
||||
namespace Json
|
||||
{
|
||||
|
||||
class Value;
|
||||
|
||||
/** Writes a Json::Value to an std::string. */
|
||||
std::string to_string (Value const&);
|
||||
|
||||
/** Output using the StyledStreamWriter. @see Json::operator>>(). */
|
||||
std::ostream& operator<< (std::ostream&, const Value& root);
|
||||
|
||||
} // Json
|
||||
|
||||
#endif // JSON_TO_STRING_H_INCLUDED
|
||||
@@ -300,8 +300,7 @@ std::string JSONRPCRequest (std::string const& strMethod, Json::Value const& par
|
||||
request[jss::method] = strMethod;
|
||||
request[jss::params] = params;
|
||||
request[jss::id] = id;
|
||||
Json::FastWriter writer;
|
||||
return writer.write (request) + "\n";
|
||||
return to_string (request) + "\n";
|
||||
}
|
||||
|
||||
std::string JSONRPCReply (Json::Value const& result, Json::Value const& error, Json::Value const& id)
|
||||
@@ -310,8 +309,7 @@ std::string JSONRPCReply (Json::Value const& result, Json::Value const& error, J
|
||||
reply[jss::result] = result;
|
||||
//reply["error"]=error;
|
||||
//reply["id"]=id;
|
||||
Json::FastWriter writer;
|
||||
return writer.write (reply) + "\n";
|
||||
return to_string (reply) + "\n";
|
||||
}
|
||||
|
||||
void ErrorReply (std::ostream& stream, Json::Value const& objError, Json::Value const& id)
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <ripple/json/impl/json_reader.cpp>
|
||||
#include <ripple/json/impl/json_value.cpp>
|
||||
#include <ripple/json/impl/json_writer.cpp>
|
||||
#include <ripple/json/impl/to_string.cpp>
|
||||
|
||||
#include <ripple/json/impl/Tests.cpp>
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <ripple/json/json_features.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
|
||||
#include <ripple/json/JsonPropertyStream.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user