Skip to content

Commit

Permalink
[FOLD] Alternate implementation of int64 Json handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Dec 21, 2017
1 parent e24689b commit a51519b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
12 changes: 6 additions & 6 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,10 +2367,10 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)

info[jss::state_accounting] = accounting_.json();
info[jss::uptime] = UptimeTimer::getInstance ().getElapsedSeconds ();
info[jss::jq_trans_overflow] = app_.overlay().getJqTransOverflow();
info[jss::peer_disconnects] = app_.overlay().getPeerDisconnect();
info[jss::peer_disconnects_resources] =
app_.overlay().getPeerDisconnectCharges();
info[jss::jq_trans_overflow].setAsString(app_.overlay().getJqTransOverflow());
info[jss::peer_disconnects].setAsString(app_.overlay().getPeerDisconnect());
info[jss::peer_disconnects_resources].setAsString(
app_.overlay().getPeerDisconnectCharges());

return info;
}
Expand Down Expand Up @@ -3368,8 +3368,8 @@ Json::Value NetworkOPsImp::StateAccounting::json() const
{
ret[states_[i]] = Json::objectValue;
auto& state = ret[states_[i]];
state[jss::transitions] = counters[i].transitions;
state[jss::duration_us] = counters[i].dur.count();
state[jss::transitions].setAsString(counters[i].transitions);
state[jss::duration_us].setAsString(counters[i].dur.count());
}

return ret;
Expand Down
18 changes: 0 additions & 18 deletions src/ripple/json/impl/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,6 @@ Value::Value ( UInt value )
value_.uint_ = value;
}

Value::Value ( std::int64_t value )
: type_ ( stringValue )
, allocated_ ( true )
{
std::string str(std::to_string(value));
value_.string_ = valueAllocator ()->duplicateStringValue (
str.c_str (), str.size() );
}

Value::Value ( std::uint64_t value )
: type_ ( stringValue )
, allocated_ ( true )
{
std::string str(std::to_string(value));
value_.string_ = valueAllocator ()->duplicateStringValue (
str.c_str (), str.size() );
}

Value::Value ( double value )
: type_ ( realValue )
{
Expand Down
22 changes: 13 additions & 9 deletions src/ripple/json/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ class Value
Value ( ValueType type = nullValue );
Value ( Int value );
Value ( UInt value );
// Convert 64bit integers to string. Json integers overflow between 32
// and 64 bits: some large integers cannot be expressed as
// a Json integer therefore.
Value ( std::int64_t value );
Value ( std::uint64_t value );
Value ( double value );
Value ( const char* value );
Value ( const char* beginValue, const char* endValue );
Expand All @@ -244,6 +239,12 @@ class Value
Value ( Value&& other ) noexcept;
Value& operator= ( Value&& other ) noexcept;

/// Convert arbitrary values to string. Intended primarily for 64 bit
/// integers. Json integers overflow between 32 and 64 bits: therefore
/// some large integers cannot be expressed as a Json integer.
template<class T>
Value& setAsString(T value);

/// Swap values.
/// \note Currently, comments are intentionally not swapped, for
/// both logic and efficiency.
Expand Down Expand Up @@ -364,10 +365,6 @@ class Value
/// \post if type() was nullValue, it remains nullValue
Members getMemberNames () const;

bool hasComment ( CommentPlacement placement ) const;
/// Include delimiters and embedded newlines.
std::string getComment ( CommentPlacement placement ) const;

std::string toStyledString () const;

const_iterator begin () const;
Expand Down Expand Up @@ -425,6 +422,13 @@ bool operator>= (const Value& x, const Value& y)
return ! (x < y);
}

template<class T>
Value&
Value::setAsString(T value)
{
return *this = std::to_string(value);
}

/** \brief Experimental do not use: Allocator to customize member name and string value memory management done by Value.
*
* - makeMemberName() and releaseMemberName() are called to respectively duplicate and
Expand Down

0 comments on commit a51519b

Please sign in to comment.