mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [mesos] lava commented on a change in pull request #326: MESOS-6874: Validate the match between Type and *Infos in the ContainerInfo.
Date Fri, 15 Mar 2019 12:58:53 GMT
lava commented on a change in pull request #326: MESOS-6874: Validate the match between Type
and *Infos in the ContainerInfo.

 File path: src/common/protobuf_utils.hpp
 @@ -64,6 +64,63 @@ struct Slave;
 namespace protobuf {
+// A "protobuf union" is a protobuf message
+// which has an enum named "Type" defined in its scope,
+// a required field named "type" of a "Type" type
+// and a field corresponding to each member of the "Type" enum.
+// A valid "protobuf union" should satisfy the following requirements.
+// 1. A member of the Type enum with a number (not index!) of 0,
+//    if there is any, should be named "UNKNOWN".
+// 2. For each other member of the Type enum there should be an optional field
+//    in the message with an exactly matching name in lowercase.
+// 3. The fields that correspond to members of the Type enum other than
+//    message.type(), should not be set.
+// NOTE: If possible, oneof should be used in the new messages instead
+// of the "protobuf union".
+class UnionValidatorHelper
+  UnionValidatorHelper(
+      const google::protobuf::Descriptor*,
+      const google::protobuf::EnumDescriptor*);
+  Option<Error> Validate(
+      const int messageTypeNumber, const google::protobuf::Message&) const;
+  std::vector<std::pair<int, const google::protobuf::FieldDescriptor*>>
+    UnionFieldDescriptors;
+  const google::protobuf::EnumDescriptor* TypeDescriptor;
+template <class Message>
+class UnionValidator
+  static Option<Error> Validate(const Message& message)
+  {
+    static const UnionValidatorHelper helper(
+        Message::descriptor(), Message::Type_descriptor());
+    return helper.Validate(message.type(), message);
+  };
+  UnionValidator() = delete;
+// This function returns Error if the protobuf union is not valid
+// and Nothing otherwise.
 Review comment:
   Let's also mention that it will abort the process if the passed message is not a protobuf
union. (which is actually the correct behaviour, I think, because getting the wrong message
type here is essentially a compile-time bug that is only detected at runtime)

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message