proto_stream.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_IO_PROTO_STREAM_H_
18 #define CARTOGRAPHER_IO_PROTO_STREAM_H_
19 
20 #include <fstream>
21 
24 #include "google/protobuf/message.h"
25 
26 namespace cartographer {
27 namespace io {
28 
29 // A simple writer of a compressed sequence of protocol buffer messages to a
30 // file. The format is not intended to be compatible with any other format used
31 // outside of Cartographer.
32 //
33 // TODO(whess): Compress the file instead of individual messages for better
34 // compression performance? Should we use LZ4?
36  public:
37  ProtoStreamWriter(const std::string& filename);
38  ~ProtoStreamWriter() = default;
39 
40  ProtoStreamWriter(const ProtoStreamWriter&) = delete;
42 
43  void WriteProto(const google::protobuf::Message& proto) override;
44  bool Close() override;
45 
46  private:
47  void Write(const std::string& uncompressed_data);
48 
49  std::ofstream out_;
50 };
51 
52 // A reader of the format produced by ProtoStreamWriter.
54  public:
55  explicit ProtoStreamReader(const std::string& filename);
56  ~ProtoStreamReader() = default;
57 
58  ProtoStreamReader(const ProtoStreamReader&) = delete;
60 
61  bool ReadProto(google::protobuf::Message* proto) override;
62  bool eof() const override;
63 
64  private:
65  bool Read(std::string* decompressed_data);
66 
67  std::ifstream in_;
68 };
69 
70 } // namespace io
71 } // namespace cartographer
72 
73 #endif // CARTOGRAPHER_IO_PROTO_STREAM_H_
ProtoStreamWriter & operator=(const ProtoStreamWriter &)=delete
ProtoStreamWriter(const std::string &filename)
Definition: proto_stream.cc:46
void Write(const std::string &uncompressed_data)
Definition: proto_stream.cc:51
void WriteProto(const google::protobuf::Message &proto) override
Definition: proto_stream.cc:58


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58