Apollo 10.0
自动驾驶开放平台
record_reader.h
浏览该文件的文档.
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
32namespace apollo {
33namespace cyber {
34namespace record {
35
39class 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_
Base class for record reader and writer.
Definition record_base.h:35
void Reset()
Reset the message index of record reader.
std::unordered_map< std::string, proto::ChannelCache > ChannelInfoMap
const std::string & GetProtoDesc(const std::string &channel_name) const override
Get proto descriptor string by channel name.
bool ReadMessage(RecordMessage *message, uint64_t begin_time=0, uint64_t end_time=std::numeric_limits< uint64_t >::max())
Read one message from reader.
bool IsValid() const
Is this record reader is valid.
std::unique_ptr< RecordFileReader > FileReaderPtr
uint64_t GetMessageNumber(const std::string &channel_name) const override
Get message number by channel name.
const std::string & GetMessageType(const std::string &channel_name) const override
Get message type by channel name.
std::set< std::string > GetChannelList() const override
Get channel list.
virtual ~RecordReader()
The destructor.
class register implement
Definition arena_queue.h:37
Basic data struct of record message.