Apollo  6.0
Open source self driving car software
record_reader.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 CYBER_RECORD_RECORD_READER_H_
18 #define CYBER_RECORD_RECORD_READER_H_
19 
20 #include <limits>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include <unordered_map>
25 
26 #include "cyber/proto/record.pb.h"
27 
31 
32 namespace apollo {
33 namespace cyber {
34 namespace record {
35 
39 class RecordReader : public RecordBase {
40  public:
41  using FileReaderPtr = std::unique_ptr<RecordFileReader>;
42  using ChannelInfoMap = std::unordered_map<std::string, proto::ChannelCache>;
43 
49  explicit RecordReader(const std::string& file);
50 
54  virtual ~RecordReader();
55 
61  bool IsValid() const { return is_valid_; }
62 
72  bool ReadMessage(RecordMessage* message, uint64_t begin_time = 0,
73  uint64_t end_time = std::numeric_limits<uint64_t>::max());
74 
78  void Reset();
79 
87  uint64_t GetMessageNumber(const std::string& channel_name) const override;
88 
96  const std::string& GetMessageType(
97  const std::string& channel_name) const override;
98 
106  const std::string& GetProtoDesc(
107  const std::string& channel_name) const override;
108 
114  std::set<std::string> GetChannelList() const override;
115 
116  private:
117  bool ReadNextChunk(uint64_t begin_time, uint64_t end_time);
118 
119  bool is_valid_ = false;
120  bool reach_end_ = false;
121  std::unique_ptr<proto::ChunkBody> chunk_ = nullptr;
122  proto::Index index_;
123  int message_index_ = 0;
124  ChannelInfoMap channel_info_;
125  FileReaderPtr file_reader_;
126 };
127 
128 } // namespace record
129 } // namespace cyber
130 } // namespace apollo
131 
132 #endif // CYBER_RECORD_RECORD_READER_H_
void Reset()
Reset the message index of record reader.
Basic data struct of record message.
Definition: record_message.h:34
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool ReadMessage(RecordMessage *message, uint64_t begin_time=0, uint64_t end_time=std::numeric_limits< uint64_t >::max())
Read one message from reader.
virtual ~RecordReader()
The destructor.
const std::string & GetProtoDesc(const std::string &channel_name) const override
Get proto descriptor string by channel name.
const std::string & GetMessageType(const std::string &channel_name) const override
Get message type by channel name.
std::unique_ptr< RecordFileReader > FileReaderPtr
Definition: record_reader.h:41
The record reader.
Definition: record_reader.h:39
Base class for record reader and writer.
Definition: record_base.h:35
std::unordered_map< std::string, proto::ChannelCache > ChannelInfoMap
Definition: record_reader.h:42
uint64_t GetMessageNumber(const std::string &channel_name) const override
Get message number by channel name.
std::set< std::string > GetChannelList() const override
Get channel list.
bool IsValid() const
Is this record reader is valid.
Definition: record_reader.h:61
RecordReader(const std::string &file)
The constructor with record file path as parameter.