14 #ifndef OR_TOOLS_PORT_PROTO_UTILS_H_
15 #define OR_TOOLS_PORT_PROTO_UTILS_H_
19 #if !defined(__PORTABLE_PLATFORM__)
20 #include "google/protobuf/generated_enum_reflection.h"
21 #include "google/protobuf/text_format.h"
25 #include "absl/strings/str_cat.h"
26 #include "absl/strings/string_view.h"
32 #if defined(__PORTABLE_PLATFORM__)
41 #if defined(__PORTABLE_PLATFORM__)
44 return message.ShortDebugString();
48 template <
typename ProtoEnumType>
50 #if defined(__PORTABLE_PLATFORM__)
51 return absl::StrCat(enum_value);
53 auto enum_descriptor = google::protobuf::GetEnumDescriptor<ProtoEnumType>();
54 auto enum_value_descriptor = enum_descriptor->FindValueByNumber(enum_value);
55 if (enum_value_descriptor ==
nullptr) {
57 "Invalid enum value of: ", enum_value,
" for enum type: ",
58 google::protobuf::GetEnumDescriptor<ProtoEnumType>()->
name());
60 return enum_value_descriptor->name();
64 template <
typename ProtoType>
67 #if defined(__PORTABLE_PLATFORM__)
70 return google::protobuf::TextFormat::MergeFromString(
71 std::string(proto_text_string),
proto);
84 template <
typename ProtoType>
86 ProtoType* message_out,
87 std::string* error_out) {
88 #if defined(__PORTABLE_PLATFORM__)
90 *message_out = ProtoType();
94 "cannot parse text protos on this platform (platform uses lite protos do "
95 "not support parsing text protos)";
102 template <
typename ProtoType>
104 #if defined(__PORTABLE_PLATFORM__)
106 "<text protos not supported with lite protobuf, cannot print proto "
108 proto.GetTypeName(),
">");
111 google::protobuf::TextFormat::PrintToString(
proto, &result);
Collection of objects used to extend the Constraint Solver library.
std::string ProtobufTextFormatPrintToString(const ProtoType proto)
bool ParseTextProtoForFlag(const absl::string_view text, google::protobuf::Message *const message_out, std::string *const error_out)
bool ProtobufParseTextProtoForFlag(absl::string_view text, ProtoType *message_out, std::string *error_out)
std::string ProtoEnumToString(ProtoEnumType enum_value)
std::string ProtobufShortDebugString(const P &message)
std::string ProtobufDebugString(const P &message)
bool ProtobufTextFormatMergeFromString(absl::string_view proto_text_string, ProtoType *proto)