> On Sept. 29, 2015, 4:17 p.m., Alexander Rukletsov wrote:
> > One high level suggestion.
> > 
> > After looking at our http code, I realized that we use the same pattern 
> > again and again, for example:
> > ```
> >     JSON::Array array;
> >     array.values.reserve(status.network_infos().size()); // MESOS-2353.
> >     foreach (const NetworkInfo& info, status.network_infos()) {
> >       array.values.push_back(model(info));
> >     }
> >     object.values["network_infos"] = std::move(array);
> > ```
> > We cannot use newly added `JSON::protobuf()` here, because a different way 
> > for rendering JSON from protobuf is used. Without digging deep inside, I 
> > know three ways how we create a `JSON` out of a proto in our codebase:
> > - wrap in `JSON::Protobuf()` for individual messages;
> > - wrap in one of the `model()` family functions;
> > - pass as it is for built-in types.
> > 
> > The proposed conversion function covers one of the possible ways. How about 
> > add one more convertion? Something like:
> > ```
> > template <typename T>
> > Array protobuf(const google::protobuf::RepeatedPtrField<T>& repeated,
> >     const lambda::function<JSON::Object>(const T&)>& converter)
> > {
> >   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(converter(elem));
> >   }
> >   
> >   return array;
> > }
> > ```
> > 
> > Then the snippet above could be rewritten as:
> > ```
> > object.values["network_infos"] = 
> > std::move(JSON::protobuf(status.network_infos(), [](const NetworkInfo& 
> > info) { return model(info); });
> > ```
> > 
> > A further improvement would be to accept any iterable collection, not only 
> > `RepeatedPtrField<>`, for example `hashset`.
> > 
> > What do you think?
> 
> Klaus Ma wrote:
>     Awesome! I've also try similar proposal, but failed when `function` 
> converting with `template`; your suggestion using lambda is great!
>     For the `hashset`, I'd suggest to address it when we have such case in 
> our code :).
>     
>     I'll also address your comments above.
> 
> Alexander Rukletsov wrote:
>     We do have such cases in our codebase ; ). Here are a few as an example:
>     - https://github.com/apache/mesos/blob/master/src/master/http.cpp#L217
>     - https://github.com/apache/mesos/blob/master/src/master/http.cpp#L229
> 
> Michael Park wrote:
>     I like the idea of taking a projection function as an argument, but let's 
> do it as a separate ticket to keep the scope of this review narrow.
> 
> Klaus Ma wrote:
>     I'll log a new ticket to trace projection fuction part.
> 
> Klaus Ma wrote:
>     MESOS-3580 is logged to trace this requirement, @alex-mesos, would you 
> shepherd it?
> 
> Alexander Rukletsov wrote:
>     Great, thanks! I'm not a Mesos committer, hence I cannot shepherd, but I 
> would love to review and help out with that! Maybe @MPark will agree to 
> shepherd?

@klaus1982: Thanks for filing MESOS-3580. I think we'll probably hold off 
working on that ticket to see if it'll still be useful after the work around 
speeding up JSON parsing/streaming.


- Michael


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/38342/#review100964
-----------------------------------------------------------


On Oct. 4, 2015, 11:29 a.m., Klaus Ma wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/38342/
> -----------------------------------------------------------
> 
> (Updated Oct. 4, 2015, 11:29 a.m.)
> 
> 
> Review request for mesos, Alexander Rukletsov, Michael Park, and Jan Schlicht.
> 
> 
> Bugs: MESOS-3405
>     https://issues.apache.org/jira/browse/MESOS-3405
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> 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.
> 
> 
> Diffs
> -----
> 
>   3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp 2285ce9 
>   3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp 68328a2 
>   3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.pb.h 8ebb798 
>   3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.pb.cc 34eb6d0 
>   3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.proto 920f5c9 
> 
> Diff: https://reviews.apache.org/r/38342/diff/
> 
> 
> Testing
> -------
> 
> cd 3rdparty/libprocess/3rdparty/stout
> ./boostrap
> ./configure
> make
> 
> 
> Thanks,
> 
> Klaus Ma
> 
>

Reply via email to