You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/12/01 06:43:35 UTC

[2/7] mesos git commit: Made `serialize()`/`deserialize()` handle streaming content types.

Made `serialize()`/`deserialize()` handle streaming content types.

The `serialize()` helper can now encode a record in 'Record-IO'
format for streaming content type. Also, `deserialize()` now
handles a streaming content type by just parsing it the body
into a corresponding protobuf.

Review: https://reviews.apache.org/r/54218/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2c2abd70
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2c2abd70
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2c2abd70

Branch: refs/heads/master
Commit: 2c2abd70962a85c959b650b6fdd6177a106809d4
Parents: dfe21b9
Author: Anand Mazumdar <an...@apache.org>
Authored: Wed Nov 30 22:41:36 2016 -0800
Committer: Anand Mazumdar <an...@apache.org>
Committed: Wed Nov 30 22:41:36 2016 -0800

----------------------------------------------------------------------
 src/common/http.cpp | 13 +++++++++++--
 src/common/http.hpp | 10 ++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2c2abd70/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 42af330..8309e5e 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -37,6 +37,7 @@
 #include <stout/duration.hpp>
 #include <stout/foreach.hpp>
 #include <stout/protobuf.hpp>
+#include <stout/recordio.hpp>
 #include <stout/stringify.hpp>
 #include <stout/unreachable.hpp>
 
@@ -72,6 +73,12 @@ ostream& operator<<(ostream& stream, ContentType contentType)
     case ContentType::JSON: {
       return stream << APPLICATION_JSON;
     }
+    case ContentType::STREAMING_PROTOBUF: {
+      return stream << APPLICATION_STREAMING_PROTOBUF;
+    }
+    case ContentType::STREAMING_JSON: {
+      return stream << APPLICATION_STREAMING_JSON;
+    }
   }
 
   UNREACHABLE();
@@ -96,10 +103,12 @@ string serialize(
     const google::protobuf::Message& message)
 {
   switch (contentType) {
-    case ContentType::PROTOBUF: {
+    case ContentType::PROTOBUF:
+    case ContentType::STREAMING_PROTOBUF: {
       return message.SerializeAsString();
     }
-    case ContentType::JSON: {
+    case ContentType::JSON:
+    case ContentType::STREAMING_JSON: {
       JSON::Object object = JSON::protobuf(message);
       return stringify(object);
     }

http://git-wip-us.apache.org/repos/asf/mesos/blob/2c2abd70/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 378208b..cb8eead 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -50,6 +50,8 @@ extern hashset<std::string> AUTHORIZABLE_ENDPOINTS;
 
 // Serializes a protobuf message for transmission
 // based on the HTTP content type.
+// NOTE: For streaming `contentType`, `message` would not
+// be serialized in "Record-IO" format.
 std::string serialize(
     ContentType contentType,
     const google::protobuf::Message& message);
@@ -57,20 +59,24 @@ std::string serialize(
 
 // Deserializes a string message into a protobuf message based on the
 // HTTP content type.
+// NOTE: For streaming `contentType`, `body` should not be
+// in "Record-IO" format.
 template <typename Message>
 Try<Message> deserialize(
     ContentType contentType,
     const std::string& body)
 {
   switch (contentType) {
-    case ContentType::PROTOBUF: {
+    case ContentType::PROTOBUF:
+    case ContentType::STREAMING_PROTOBUF: {
       Message message;
       if (!message.ParseFromString(body)) {
         return Error("Failed to parse body into a protobuf object");
       }
       return message;
     }
-    case ContentType::JSON: {
+    case ContentType::JSON:
+    case ContentType::STREAMING_JSON: {
       Try<JSON::Value> value = JSON::parse(body);
       if (value.isError()) {
         return Error("Failed to parse body into JSON: " + value.error());