14#ifndef OR_TOOLS_PORT_PROTO_UTILS_H_
15#define OR_TOOLS_PORT_PROTO_UTILS_H_
19#if !defined(__PORTABLE_PLATFORM__)
23#include "absl/strings/str_cat.h"
24#include "absl/strings/string_view.h"
25#include "google/protobuf/message.h"
26#include "google/protobuf/message_lite.h"
27#include "google/protobuf/text_format.h"
33#if defined(__PORTABLE_PLATFORM__)
42#if defined(__PORTABLE_PLATFORM__)
45 return message.ShortDebugString();
49template <
typename ProtoEnumType>
51#if defined(__PORTABLE_PLATFORM__)
52 return absl::StrCat(enum_value);
54 auto enum_descriptor = google::protobuf::GetEnumDescriptor<ProtoEnumType>();
55 auto enum_value_descriptor = enum_descriptor->FindValueByNumber(enum_value);
56 if (enum_value_descriptor ==
nullptr) {
58 "Invalid enum value of: ", enum_value,
" for enum type: ",
59 google::protobuf::GetEnumDescriptor<ProtoEnumType>()->
name());
61 return enum_value_descriptor->name();
65template <
typename ProtoType>
68#if defined(__PORTABLE_PLATFORM__)
71 return google::protobuf::TextFormat::MergeFromString(
72 std::string(proto_text_string),
proto);
85template <
typename ProtoType>
87 ProtoType* message_out,
88 std::string* error_out) {
89#if defined(__PORTABLE_PLATFORM__)
91 *message_out = ProtoType();
95 "cannot parse text protos on this platform (platform uses lite protos do "
96 "not support parsing text protos)";
106 const google::protobuf::Message&
proto);
110 const google::protobuf::MessageLite&
proto);
CpModelProto proto
The output proto.
const std::string name
A name for logging purposes.
In SWIG mode, we don't want anything besides these top-level includes.
bool ParseTextProtoForFlag(const absl::string_view text, google::protobuf::Message *const message_out, std::string *const error_out)
std::string ProtobufTextFormatPrintToStringForFlag(const google::protobuf::Message &proto)
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)