14 #ifndef OR_TOOLS_UTIL_FILE_UTIL_H_
15 #define OR_TOOLS_UTIL_FILE_UTIL_H_
20 #include "absl/status/statusor.h"
21 #include "absl/strings/string_view.h"
22 #include "google/protobuf/message.h"
38 google::protobuf::Message*
proto);
40 template <
typename Proto>
55 const google::protobuf::Message&
proto,
57 bool append_extension_to_file_name =
true);
63 template <
typename Proto>
66 std::vector<Proto> protos;
69 while (num_read != expected_num_records &&
71 protos.push_back(
proto);
76 <<
"File '" <<
file->filename()
77 <<
"'was not fully read, or something went wrong when closing "
78 "it. Is it the right format? (RecordIO of Protocol Buffers).";
80 if (expected_num_records >= 0) {
81 CHECK_EQ(num_read, expected_num_records)
82 <<
"There were less than the expected " << expected_num_records
90 template <
typename Proto>
92 int expected_num_records) {
94 expected_num_records);
101 template <
typename Proto>
103 return internal::ReadNumRecords<Proto>(filename, -1);
105 template <
typename Proto>
107 return internal::ReadNumRecords<Proto>(
file, -1);
113 template <
typename Proto>
116 p.Swap(&internal::ReadNumRecords<Proto>(filename, 1)[0]);
122 template <
typename Proto>
124 const std::vector<Proto>& protos) {
127 for (
const Proto&
proto : protos) {
135 #endif // OR_TOOLS_UTIL_FILE_UTIL_H_