14 #ifndef OR_TOOLS_UTIL_PROTO_TOOLS_H_ 15 #define OR_TOOLS_UTIL_PROTO_TOOLS_H_ 19 #include "absl/status/status.h" 20 #include "absl/status/statusor.h" 21 #include "absl/strings/str_format.h" 22 #include "google/protobuf/message.h" 30 template <
class Proto>
32 template <
class Proto>
34 const google::protobuf::Message*
proto);
40 const google::protobuf::Message&
message,
int indent_level);
45 template <
class Proto>
47 const google::protobuf::Descriptor* expected_descriptor =
48 Proto::default_instance().GetDescriptor();
49 const google::protobuf::Descriptor* actual_descriptor =
50 proto->GetDescriptor();
51 if (actual_descriptor == expected_descriptor)
52 return reinterpret_cast<Proto*>(
proto);
53 return absl::InvalidArgumentError(absl::StrFormat(
54 "Expected message type '%s', but got type '%s'",
55 expected_descriptor->full_name(), actual_descriptor->full_name()));
58 template <
class Proto>
60 const google::protobuf::Message*
proto) {
61 const google::protobuf::Descriptor* expected_descriptor =
62 Proto::default_instance().GetDescriptor();
63 const google::protobuf::Descriptor* actual_descriptor =
64 proto->GetDescriptor();
65 if (actual_descriptor == expected_descriptor) {
66 return reinterpret_cast<const Proto*>(
proto);
68 return absl::InvalidArgumentError(absl::StrFormat(
69 "Expected message type '%s', but got type '%s'",
70 expected_descriptor->full_name(), actual_descriptor->full_name()));
74 #endif // OR_TOOLS_UTIL_PROTO_TOOLS_H_ absl::StatusOr< Proto * > SafeProtoDownCast(google::protobuf::Message *proto)
absl::StatusOr< const Proto * > SafeProtoConstDownCast(const google::protobuf::Message *proto)
Collection of objects used to extend the Constraint Solver library.
std::string FullProtocolMessageAsString(const google::protobuf::Message &message, int indent_level)