Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
recordio.cc
Go to the documentation of this file.
1// Copyright 2010-2025 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
15
16#include <cstdint>
17#include <istream>
18#include <ostream>
19
20#include "google/protobuf/message_lite.h"
21
22namespace operations_research {
23namespace sat {
24
25RecordReader::RecordReader(std::istream* istream)
26 : istream_(istream), coded_istream_(&istream_) {}
27
28bool RecordReader::ReadRecord(google::protobuf::MessageLite* record) {
29 uint32_t size;
30 if (!coded_istream_.ReadVarint32(&size)) return false;
31 auto limit = coded_istream_.PushLimit(size);
32 if (!record->ParseFromCodedStream(&coded_istream_)) return false;
33 coded_istream_.PopLimit(limit);
34 return true;
35}
36
38
39RecordWriter::RecordWriter(std::ostream* ostream)
40 : ostream_(ostream), coded_ostream_(&ostream_) {}
41
42bool RecordWriter::WriteRecord(const google::protobuf::MessageLite& record) {
43 coded_ostream_.WriteVarint32(record.ByteSizeLong());
44 return record.SerializeToCodedStream(&coded_ostream_);
45}
46
47void RecordWriter::Close() { coded_ostream_.Trim(); }
48
49} // namespace sat
50} // namespace operations_research
RecordReader(std::istream *istream)
Definition recordio.cc:25
bool ReadRecord(google::protobuf::MessageLite *record)
Definition recordio.cc:28
bool WriteRecord(const google::protobuf::MessageLite &record)
Definition recordio.cc:42
RecordWriter(std::ostream *ostream)
Definition recordio.cc:39
OR-Tools root namespace.