14#ifndef OR_TOOLS_BASE_RECORDIO_H_
15#define OR_TOOLS_BASE_RECORDIO_H_
42 std::string uncompressed_buffer;
43 proto.SerializeToString(&uncompressed_buffer);
44 const uint64_t uncompressed_size = uncompressed_buffer.size();
45 const std::string compressed_buffer =
46 use_compression_ ? Compress(uncompressed_buffer) :
"";
47 const uint64_t compressed_size = compressed_buffer.size();
52 if (file_->
Write(&uncompressed_size,
sizeof(uncompressed_size)) !=
53 sizeof(uncompressed_size)) {
56 if (file_->
Write(&compressed_size,
sizeof(compressed_size)) !=
57 sizeof(compressed_size)) {
60 if (use_compression_) {
61 if (file_->
Write(compressed_buffer.c_str(), compressed_size) !=
66 if (file_->
Write(uncompressed_buffer.c_str(), uncompressed_size) !=
79 std::string Compress(
const std::string&
input)
const;
81 bool use_compression_;
95 if (file_->
Read(&magic_number,
sizeof(magic_number)) !=
96 sizeof(magic_number)) {
102 if (file_->
Read(&usize,
sizeof(usize)) !=
sizeof(usize)) {
105 if (file_->
Read(&csize,
sizeof(csize)) !=
sizeof(csize)) {
108 std::unique_ptr<char[]> buffer(
new char[usize + 1]);
110 std::unique_ptr<char[]> compressed_buffer(
new char[csize + 1]);
111 if (file_->
Read(compressed_buffer.get(), csize) != csize) {
114 compressed_buffer[csize] =
'\0';
115 Uncompress(compressed_buffer.get(), csize, buffer.get(), usize);
117 if (file_->
Read(buffer.get(), usize) != usize) {
121 proto->ParseFromArray(buffer.get(), usize);
129 void Uncompress(
const char*
const source, uint64_t source_size,
130 char*
const output_buffer, uint64_t output_size)
const;
size_t Write(const void *buff, size_t size)
Writes "size" bytes of buff to file, buff should be pre-allocated.
size_t Read(void *buff, size_t size)
Reads "size" bytes to buff from file, buff should be pre-allocated.
RecordReader(File *const file)
bool Close()
Closes the underlying file.
bool ReadProtocolMessage(P *const proto)
void set_use_compression(bool use_compression)
bool Close()
Closes the underlying file.
bool WriteProtocolMessage(const P &proto)
static const int kMagicNumber
Magic number when reading and writing protocol buffers.
RecordWriter(File *const file)
CpModelProto proto
The output proto.
static int input(yyscan_t yyscanner)