You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "Klaus Ma (JIRA)" <ji...@apache.org> on 2015/09/13 08:16:45 UTC
[jira] [Commented] (MESOS-3405) Add JSON::protobuf for
google::protobuf::RepeatedPtrField.
[ https://issues.apache.org/jira/browse/MESOS-3405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14742365#comment-14742365 ]
Klaus Ma commented on MESOS-3405:
---------------------------------
[~mcypark], I'm working on the patch for this ticket; after checking the code, I'd like to do the following enhancement:
- Move {{JSON::Protobuf}} to {{JSON::internal::Protobuf}} to make it internal
- Replace {{JSON::Protobuf}} with {{JSON::protobuf}}
- Add serialize function to {{Array protobuf(const google::protobuf::RepeatedPtrField<T>& repeated)}}, so the following code can be re-used
{code}
{
JSON::Array array;
array.values.reserve(task.statuses().size()); // MESOS-2353.
foreach (const TaskStatus& status, task.statuses()) {
array.values.push_back(model(status)); // <=== add model as protobuf's second parameter.
}
object.values["statuses"] = std::move(array);
}
{code}
After this refactor, {{make && make check}} is enough for the UT.
If any comments, please let me know.
> Add JSON::protobuf for google::protobuf::RepeatedPtrField.
> ----------------------------------------------------------
>
> Key: MESOS-3405
> URL: https://issues.apache.org/jira/browse/MESOS-3405
> Project: Mesos
> Issue Type: Task
> Components: stout
> Reporter: Michael Park
> Assignee: Klaus Ma
>
> Currently, {{stout/protobuf.hpp}} provides a {{JSON::Protobuf}} utility which converts a {{google::protobuf::Message}} into a {{JSON::Object}}.
> We should add the support for {{google::protobuf::RepeatedPtrField<T>}} by introducing overloaded functions.
> {code}
> namespace JSON {
> Object protobuf(const google::protobuf::Message& message)
> {
> Object object;
> /* Move the body of JSON::Protobuf constructor here. */
> return object;
> }
> template <typename T>
> Array protobuf(const google::protobuf::RepeatedPtrField<T>& repeated)
> {
> static_assert(std::is_convertible<T*, google::protobuf::Message*>::value,
> "T must be a google::protobuf::Message");
> JSON::Array array;
> array.values.reserve(repeated.size());
> foreach (const T& elem, repeated) {
> array.values.push_back(JSON::Protobuf(elem));
> }
> return array;
> }
> }
> {code}
> The new {{RepeatedPtrField}} version can be used in at least the following places:
> * {{src/common/http.cpp}}
> * {{src/master/http.cpp}}
> * {{src/slave/containerizer/mesos/containerizer.cpp}}
> * {{src/tests/reservation_endpoints_tests.cpp}}
> * {{src/tests/resources_tests.cpp}}: {{ResourcesTest.ParsingFromJSON}}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)