14 #ifndef OR_TOOLS_UTIL_FILE_UTIL_H_
15 #define OR_TOOLS_UTIL_FILE_UTIL_H_
21 #include "absl/status/statusor.h"
22 #include "absl/strings/string_view.h"
23 #include "google/protobuf/message.h"
40 google::protobuf::Message*
proto);
42 template <
typename Proto>
59 const google::protobuf::Message&
proto,
61 bool append_extension_to_file_name =
true);
67 template <
typename Proto>
70 std::vector<Proto> protos;
73 while (num_read != expected_num_records &&
75 protos.push_back(
proto);
80 <<
"File '" <<
file->filename()
81 <<
"'was not fully read, or something went wrong when closing "
82 "it. Is it the right format? (RecordIO of Protocol Buffers).";
84 if (expected_num_records >= 0) {
85 CHECK_EQ(num_read, expected_num_records)
86 <<
"There were less than the expected " << expected_num_records
94 template <
typename Proto>
96 int expected_num_records) {
98 expected_num_records);
105 template <
typename Proto>
107 return internal::ReadNumRecords<Proto>(filename, -1);
109 template <
typename Proto>
111 return internal::ReadNumRecords<Proto>(
file, -1);
117 template <
typename Proto>
120 p.Swap(&internal::ReadNumRecords<Proto>(filename, 1)[0]);
126 template <
typename Proto>
128 const std::vector<Proto>& protos) {
131 for (
const Proto&
proto : protos) {
134 CHECK(writer.
Close());
bool ReadProtocolMessage(P *const proto)
bool WriteProtocolMessage(const P &proto)
File * OpenOrDie(const absl::string_view &filename, const absl::string_view &mode, int flags)
std::vector< Proto > ReadNumRecords(File *file, int expected_num_records)
Collection of objects used to extend the Constraint Solver library.
std::vector< Proto > ReadAllRecordsOrDie(absl::string_view filename)
Proto ReadFileToProtoOrDie(absl::string_view filename)
absl::StatusOr< std::string > ReadFileToString(absl::string_view filename)
bool WriteProtoToFile(absl::string_view filename, const google::protobuf::Message &proto, ProtoWriteFormat proto_write_format, bool gzipped, bool append_extension_to_file_name)
void WriteRecordsOrDie(absl::string_view filename, const std::vector< Proto > &protos)
bool ReadFileToProto(absl::string_view filename, google::protobuf::Message *proto)
Proto ReadOneRecordOrDie(absl::string_view filename)