You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/08/26 04:56:33 UTC
[1/2] git commit: Refactored the JSON output streaming.
Repository: mesos
Updated Branches:
refs/heads/master d5bbc3549 -> 7de27508f
Refactored the JSON output streaming.
Review: https://reviews.apache.org/r/24877
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/73da21e4
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/73da21e4
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/73da21e4
Branch: refs/heads/master
Commit: 73da21e4ca9c152f67858802629452c24ecc6daf
Parents: d5bbc35
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Tue Aug 19 18:33:12 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Mon Aug 25 18:47:40 2014 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/json.hpp | 170 ++++++++-----------
1 file changed, 75 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/73da21e4/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
index d98d953..719aa96 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
@@ -153,25 +153,25 @@ typedef boost::variant<boost::recursive_wrapper<Null>,
struct Value : internal::Variant
{
- // Empty constructur gets the variant default.
+ // Empty constructor gets the variant default.
Value() {}
- // bool creates a JSON::Boolean explicitly.
Value(bool value) : internal::Variant(JSON::Boolean(value)) {}
- // CStrings create a JSON::String explicitly.
Value(char* value) : internal::Variant(JSON::String(value)) {}
Value(const char* value) : internal::Variant(JSON::String(value)) {}
// Arithmetic types are specifically routed through Number because
- // there would be ambiguity between JSON::Bool and JSON::Number otherwise.
+ // there would be ambiguity between JSON::Bool and JSON::Number
+ // otherwise.
template <typename T>
Value(
const T& value,
typename boost::enable_if<boost::is_arithmetic<T>, int>::type = 0)
: internal::Variant(Number(value)) {}
- // Non-arithmetic types are passed to the default constructor of Variant.
+ // Non-arithmetic types are passed to the default constructor of
+ // Variant.
template <typename T>
Value(
const T& value,
@@ -309,116 +309,96 @@ inline bool operator == (const Value& lhs, const Value& rhs)
}
-// Implementation of rendering JSON objects built above using standard
-// C++ output streams. The visitor pattern is used thanks to to build
-// a "renderer" with boost::static_visitor and two top-level render
-// routines are provided for rendering JSON objects and arrays.
-
-struct Renderer : boost::static_visitor<>
+inline std::ostream& operator << (std::ostream& out, const String& string)
{
- Renderer(std::ostream& _out) : out(_out) {}
-
- void operator () (const String& string) const
- {
- // TODO(benh): This escaping DOES NOT handle unicode, it encodes as ASCII.
- // See RFC4627 for the JSON string specificiation.
- out << "\"";
- foreach (unsigned char c, string.value) {
- switch (c) {
- case '"': out << "\\\""; break;
- case '\\': out << "\\\\"; break;
- case '/': out << "\\/"; break;
- case '\b': out << "\\b"; break;
- case '\f': out << "\\f"; break;
- case '\n': out << "\\n"; break;
- case '\r': out << "\\r"; break;
- case '\t': out << "\\t"; break;
- default:
- // See RFC4627 for these ranges.
- if ((c >= 0x20 && c <= 0x21) ||
- (c >= 0x23 && c <= 0x5B) ||
- (c >= 0x5D && c < 0x7F)) {
- out << c;
- } else {
- // NOTE: We also escape all bytes > 0x7F since they imply more than
- // 1 byte in UTF-8. This is why we don't escape UTF-8 properly.
- // See RFC4627 for the escaping format: \uXXXX (X is a hex digit).
- // Each byte here will be of the form: \u00XX (this is why we need
- // setw and the cast to unsigned int).
- out << "\\u" << std::setfill('0') << std::setw(4)
- << std::hex << std::uppercase << (unsigned int) c;
- }
- break;
- }
+ // TODO(benh): This escaping DOES NOT handle unicode, it encodes as ASCII.
+ // See RFC4627 for the JSON string specificiation.
+ out << "\"";
+ foreach (unsigned char c, string.value) {
+ switch (c) {
+ case '"': out << "\\\""; break;
+ case '\\': out << "\\\\"; break;
+ case '/': out << "\\/"; break;
+ case '\b': out << "\\b"; break;
+ case '\f': out << "\\f"; break;
+ case '\n': out << "\\n"; break;
+ case '\r': out << "\\r"; break;
+ case '\t': out << "\\t"; break;
+ default:
+ // See RFC4627 for these ranges.
+ if ((c >= 0x20 && c <= 0x21) ||
+ (c >= 0x23 && c <= 0x5B) ||
+ (c >= 0x5D && c < 0x7F)) {
+ out << c;
+ } else {
+ // NOTE: We also escape all bytes > 0x7F since they imply more than
+ // 1 byte in UTF-8. This is why we don't escape UTF-8 properly.
+ // See RFC4627 for the escaping format: \uXXXX (X is a hex digit).
+ // Each byte here will be of the form: \u00XX (this is why we need
+ // setw and the cast to unsigned int).
+ out << "\\u" << std::setfill('0') << std::setw(4)
+ << std::hex << std::uppercase << (unsigned int) c;
+ }
+ break;
}
- out << "\"";
}
+ out << "\"";
+ return out;
+}
- void operator () (const Number& number) const
- {
- // Use the guaranteed accurate precision, see:
- // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
- out << std::setprecision(std::numeric_limits<double>::digits10)
- << number.value;
- }
- void operator () (const Object& object) const
- {
- out << "{";
- std::map<std::string, Value>::const_iterator iterator;
- iterator = object.values.begin();
- while (iterator != object.values.end()) {
- out << "\"" << (*iterator).first << "\":";
- boost::apply_visitor(Renderer(out), (*iterator).second);
- if (++iterator != object.values.end()) {
- out << ",";
- }
- }
- out << "}";
- }
+inline std::ostream& operator << (std::ostream& out, const Number& number)
+{
+ // Use the guaranteed accurate precision, see:
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
+ return out << std::setprecision(std::numeric_limits<double>::digits10)
+ << number.value;
+}
- void operator () (const Array& array) const
- {
- out << "[";
- std::list<Value>::const_iterator iterator;
- iterator = array.values.begin();
- while (iterator != array.values.end()) {
- boost::apply_visitor(Renderer(out), *iterator);
- if (++iterator != array.values.end()) {
- out << ",";
- }
+
+inline std::ostream& operator << (std::ostream& out, const Object& object)
+{
+ out << "{";
+ std::map<std::string, Value>::const_iterator iterator;
+ iterator = object.values.begin();
+ while (iterator != object.values.end()) {
+ out << "\"" << (*iterator).first << "\":" << (*iterator).second;
+ if (++iterator != object.values.end()) {
+ out << ",";
}
- out << "]";
}
+ out << "}";
+ return out;
+}
- void operator () (const Boolean& boolean) const
- {
- out << (boolean.value ? "true" : "false");
- }
- void operator () (const Null&) const
- {
- out << "null";
+inline std::ostream& operator << (std::ostream& out, const Array& array)
+{
+ out << "[";
+ std::list<Value>::const_iterator iterator;
+ iterator = array.values.begin();
+ while (iterator != array.values.end()) {
+ out << *iterator;
+ if (++iterator != array.values.end()) {
+ out << ",";
+ }
}
-
-private:
- std::ostream& out;
-};
+ out << "]";
+ return out;
+}
-inline void render(std::ostream& out, const Value& value)
+inline std::ostream& operator << (std::ostream& out, const Boolean& boolean)
{
- boost::apply_visitor(Renderer(out), value);
+ return out << (boolean.value ? "true" : "false");
}
-inline std::ostream& operator << (std::ostream& out, const Value& value)
+inline std::ostream& operator << (std::ostream& out, const Null&)
{
- render(out, value);
- return out;
+ return out << "null";
}
-
namespace internal {
inline Value convert(const picojson::value& value)
[2/2] git commit: Adjustments for new JSON streaming.
Posted by bm...@apache.org.
Adjustments for new JSON streaming.
Review: https://reviews.apache.org/r/25053
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7de27508
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7de27508
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7de27508
Branch: refs/heads/master
Commit: 7de27508fd4f6ddb1434c8e23f61985b72bc3f6e
Parents: 73da21e
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Tue Aug 19 18:33:33 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Mon Aug 25 18:50:17 2014 -0700
----------------------------------------------------------------------
3rdparty/libprocess/include/process/http.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7de27508/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 6358e33..05a3261 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -194,7 +194,7 @@ struct OK : Response
out << jsonp.get() << "(";
}
- JSON::render(out, value);
+ out << value;
if (jsonp.isSome()) {
out << ");";