Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-3405

Add JSON::protobuf for google::protobuf::RepeatedPtrField.

    Details

    • Type: Task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.26.0
    • Component/s: stout
    • Labels:
      None

      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.

      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;
        }
      }
      

      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

        Attachments

          Activity

            People

            • Assignee:
              klaus1982 Klaus Ma
              Reporter:
              mcypark Michael Park
              Shepherd:
              Michael Park
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: