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"
31 template <
class Proto>
33 template <
class Proto>
35 const google::protobuf::Message*
proto);
41 const google::protobuf::Message&
message,
int indent_level);
46 template <
class Proto>
48 const google::protobuf::Descriptor* expected_descriptor =
49 Proto::default_instance().GetDescriptor();
50 const google::protobuf::Descriptor* actual_descriptor =
51 proto->GetDescriptor();
52 if (actual_descriptor == expected_descriptor)
53 return reinterpret_cast<Proto*
>(
proto);
54 return absl::InvalidArgumentError(absl::StrFormat(
55 "Expected message type '%s', but got type '%s'",
56 expected_descriptor->full_name(), actual_descriptor->full_name()));
59 template <
class Proto>
61 const google::protobuf::Message*
proto) {
62 const google::protobuf::Descriptor* expected_descriptor =
63 Proto::default_instance().GetDescriptor();
64 const google::protobuf::Descriptor* actual_descriptor =
65 proto->GetDescriptor();
66 if (actual_descriptor == expected_descriptor) {
67 return reinterpret_cast<const Proto*
>(
proto);
69 return absl::InvalidArgumentError(absl::StrFormat(
70 "Expected message type '%s', but got type '%s'",
71 expected_descriptor->full_name(), actual_descriptor->full_name()));
75 #endif // OR_TOOLS_UTIL_PROTO_TOOLS_H_