Apollo 10.0
自动驾驶开放平台
apollo::cyber::record::Recoverer类 参考

#include <recoverer.h>

apollo::cyber::record::Recoverer 的协作图:

Public 成员函数

 Recoverer (const std::string &input_file, const std::string &output_file)
 
virtual ~Recoverer ()
 
bool Proc ()
 

详细描述

在文件 recoverer.h39 行定义.

构造及析构函数说明

◆ Recoverer()

apollo::cyber::record::Recoverer::Recoverer ( const std::string &  input_file,
const std::string &  output_file 
)

在文件 recoverer.cc30 行定义.

32 : input_file_(input_file), output_file_(output_file) {}

◆ ~Recoverer()

apollo::cyber::record::Recoverer::~Recoverer ( )
virtual

在文件 recoverer.cc34 行定义.

34{}

成员函数说明

◆ Proc()

bool apollo::cyber::record::Recoverer::Proc ( )

在文件 recoverer.cc36 行定义.

36 {
37 if (!reader_.Open(input_file_)) {
38 AERROR << "open input file failed, file: " << input_file_;
39 return false;
40 }
41
42 // open output file
43 proto::Header new_hdr = HeaderBuilder::GetHeader();
44 if (!writer_.Open(output_file_)) {
45 AERROR << "open output file failed. file: " << output_file_;
46 return false;
47 }
48 if (!writer_.WriteHeader(new_hdr)) {
49 AERROR << "write header to output file failed. file: " << output_file_;
50 return false;
51 }
52
53 // write channel sections
54 if (reader_.ReadIndex()) {
55 proto::Index index = reader_.GetIndex();
56 FOR_EACH(i, 0, index.indexes_size()) {
57 proto::SingleIndex* single_index = index.mutable_indexes(i);
58 if (single_index->type() != SectionType::SECTION_CHANNEL) {
59 continue;
60 }
61 ChannelCache* chan_cache = single_index->mutable_channel_cache();
62 if (std::find(channel_vec_.begin(), channel_vec_.end(),
63 chan_cache->name()) == channel_vec_.end()) {
64 channel_vec_.push_back(chan_cache->name());
65 Channel chan;
66 chan.set_name(chan_cache->name());
67 chan.set_message_type(chan_cache->message_type());
68 chan.set_proto_desc(chan_cache->proto_desc());
69 writer_.WriteChannel(chan);
70 }
71 }
72 }
73
74 // read through record file
75 reader_.Reset();
76 while (!reader_.EndOfFile()) {
77 Section section;
78 if (!reader_.ReadSection(&section)) {
79 AINFO << "read section failed, try next.";
80 continue;
81 }
82 if (section.type == SectionType::SECTION_INDEX) {
83 break;
84 }
85 switch (section.type) {
86 case SectionType::SECTION_CHANNEL: {
87 Channel chan;
88 if (!reader_.ReadSection<Channel>(section.size, &chan)) {
89 AINFO << "one channel section broken, skip it.";
90 break;
91 }
92 if (std::find(channel_vec_.begin(), channel_vec_.end(), chan.name()) ==
93 channel_vec_.end()) {
94 channel_vec_.push_back(chan.name());
95 writer_.WriteChannel(chan);
96 }
97 break;
98 }
99 case SectionType::SECTION_CHUNK_HEADER: {
100 ChunkHeader chdr;
101 if (!reader_.ReadSection<ChunkHeader>(section.size, &chdr)) {
102 AINFO << "one chunk header section broken, skip it.";
103 }
104 break;
105 }
106 case SectionType::SECTION_CHUNK_BODY: {
107 ChunkBody cbd;
108 if (!reader_.ReadSection<ChunkBody>(section.size, &cbd)) {
109 AINFO << "one chunk body section broken, skip it";
110 break;
111 }
112 for (int idx = 0; idx < cbd.messages_size(); ++idx) {
113 if (!writer_.WriteMessage(cbd.messages(idx))) {
114 AERROR << "add new message failed.";
115 return false;
116 }
117 }
118 break;
119 }
120 default: {
121 AERROR << "this section should not be here, section type: "
122 << section.type;
123 return false;
124 }
125 } // end for switch
126 } // end for while
127 AINFO << "recover record file done.";
128 return true;
129} // end for Proc()
static proto::Header GetHeader()
Build a default record header.
const proto::Index & GetIndex() const
bool Open(const std::string &path) override
bool Open(const std::string &path) override
bool WriteHeader(const proto::Header &header)
bool WriteChannel(const proto::Channel &channel)
bool WriteMessage(const proto::SingleMessage &message)
#define FOR_EACH(i, begin, end)
Definition for_each.h:44
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

该类的文档由以下文件生成: