Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
proto_utils.cc
Go to the documentation of this file.
1
// Copyright 2010-2024 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
#include "
ortools/port/proto_utils.h
"
15
16
#include <string>
17
18
#include "absl/strings/ascii.h"
19
#include "absl/strings/str_cat.h"
20
#include "google/protobuf/message.h"
21
#include "google/protobuf/message_lite.h"
22
#include "google/protobuf/text_format.h"
23
24
namespace
operations_research
{
25
26
std::string
ProtobufTextFormatPrintToStringForFlag
(
27
const
google::protobuf::Message&
proto
) {
28
std::string result;
29
google::protobuf::TextFormat::Printer printer;
30
printer.SetSingleLineMode(
true
);
31
printer.PrintToString(
proto
, &result);
32
// TextFormat may add an empty space at the end of the string (e.g. "cpu: 3.5
33
// "), likely because it always add a space after each field; we simply remove
34
// it here.
35
absl::StripTrailingAsciiWhitespace(&result);
36
return
result;
37
}
38
39
std::string
ProtobufTextFormatPrintToStringForFlag
(
40
const
google::protobuf::MessageLite&
proto
) {
41
return
absl::StrCat(
42
"<text protos not supported with lite protobuf, cannot print proto "
43
"message of type "
,
44
proto
.GetTypeName(),
">"
);
45
}
46
47
}
// namespace operations_research
proto
CpModelProto proto
The output proto.
Definition
cp_model_fz_solver.cc:128
operations_research
In SWIG mode, we don't want anything besides these top-level includes.
Definition
binary_indexed_tree.h:21
operations_research::ProtobufTextFormatPrintToStringForFlag
std::string ProtobufTextFormatPrintToStringForFlag(const google::protobuf::Message &proto)
Definition
proto_utils.cc:26
proto_utils.h
ortools
port
proto_utils.cc
Generated by
1.12.0