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

#include <record_file_reader.h>

类 apollo::cyber::record::RecordFileReader 继承关系图:
apollo::cyber::record::RecordFileReader 的协作图:

Public 成员函数

 RecordFileReader ()=default
 
virtual ~RecordFileReader ()
 
bool Open (const std::string &path) override
 
void Close () override
 
bool Reset ()
 
bool ReadSection (Section *section)
 
bool SkipSection (int64_t size)
 
template<typename T >
bool ReadSection (int64_t size, T *message)
 
bool ReadIndex ()
 
bool EndOfFile ()
 
- Public 成员函数 继承自 apollo::cyber::record::RecordFileBase
 RecordFileBase ()=default
 
virtual ~RecordFileBase ()=default
 
const std::string & GetPath () const
 
const proto::HeaderGetHeader () const
 
const proto::IndexGetIndex () const
 
int64_t CurrentPosition ()
 
bool SetPosition (int64_t position)
 

额外继承的成员函数

- Protected 属性 继承自 apollo::cyber::record::RecordFileBase
std::mutex mutex_
 
std::string path_
 
proto::Header header_
 
proto::Index index_
 
int fd_ = -1
 

详细描述

在文件 record_file_reader.h45 行定义.

构造及析构函数说明

◆ RecordFileReader()

apollo::cyber::record::RecordFileReader::RecordFileReader ( )
default

◆ ~RecordFileReader()

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

在文件 record_file_reader.cc150 行定义.

150 {
151 Close();
152}

成员函数说明

◆ Close()

void apollo::cyber::record::RecordFileReader::Close ( )
overridevirtual

实现了 apollo::cyber::record::RecordFileBase.

在文件 record_file_reader.cc48 行定义.

48 {
49 if (fd_ >= 0) {
50 close(fd_);
51 fd_ = -1;
52 }
53}

◆ EndOfFile()

bool apollo::cyber::record::RecordFileReader::EndOfFile ( )
inline

在文件 record_file_reader.h57 行定义.

57{ return end_of_file_; }

◆ Open()

bool apollo::cyber::record::RecordFileReader::Open ( const std::string &  path)
overridevirtual

实现了 apollo::cyber::record::RecordFileBase.

在文件 record_file_reader.cc27 行定义.

27 {
28 std::lock_guard<std::mutex> lock(mutex_);
29 path_ = path;
31 AERROR << "File not exist, file: " << path_;
32 return false;
33 }
34 fd_ = open(path_.data(), O_RDONLY);
35 if (fd_ < 0) {
36 AERROR << "Open file failed, file: " << path_ << ", fd: " << fd_
37 << ", errno: " << errno;
38 return false;
39 }
40 end_of_file_ = false;
41 if (!ReadHeader()) {
42 AERROR << "Read header section fail, file: " << path_;
43 return false;
44 }
45 return true;
46}
#define AERROR
Definition log.h:44
bool PathExists(const std::string &path)
Check if the path exists.
Definition file.cc:195

◆ ReadIndex()

bool apollo::cyber::record::RecordFileReader::ReadIndex ( )

在文件 record_file_reader.cc89 行定义.

89 {
90 if (!header_.is_complete()) {
91 AERROR << "Record file is not complete.";
92 return false;
93 }
95 AERROR << "Skip bytes for reaching the index section failed.";
96 return false;
97 }
98 Section section;
99 if (!ReadSection(&section)) {
100 AERROR << "Read index section fail, maybe file is broken.";
101 return false;
102 }
103 if (section.type != SectionType::SECTION_INDEX) {
104 AERROR << "Check section type failed"
105 << ", expect: " << SectionType::SECTION_INDEX
106 << ", actual: " << section.type;
107 return false;
108 }
109 if (!ReadSection<proto::Index>(section.size, &index_)) {
110 AERROR << "Read index section fail.";
111 return false;
112 }
113 Reset();
114 return true;
115}
optional uint64 index_position
Definition record.proto:68

◆ ReadSection() [1/2]

template<typename T >
bool apollo::cyber::record::RecordFileReader::ReadSection ( int64_t  size,
T *  message 
)

在文件 record_file_reader.h65 行定义.

65 {
66 if (size < std::numeric_limits<int>::min() ||
67 size > std::numeric_limits<int>::max()) {
68 AERROR << "Size value greater than the range of int value.";
69 return false;
70 }
71 FileInputStream raw_input(fd_, static_cast<int>(size));
72 CodedInputStream coded_input(&raw_input);
73 CodedInputStream::Limit limit = coded_input.PushLimit(static_cast<int>(size));
74 if (!message->ParseFromCodedStream(&coded_input)) {
75 AERROR << "Parse section message failed.";
76 end_of_file_ = coded_input.ExpectAtEnd();
77 return false;
78 }
79 if (!coded_input.ConsumedEntireMessage()) {
80 AERROR << "Do not consumed entire message.";
81 return false;
82 }
83 coded_input.PopLimit(limit);
84 if (static_cast<int64_t>(message->ByteSizeLong()) != size) {
85 AERROR << "Message size is not consistent in section header"
86 << ", expect: " << size << ", actual: " << message->ByteSizeLong();
87 return false;
88 }
89 return true;
90}

◆ ReadSection() [2/2]

bool apollo::cyber::record::RecordFileReader::ReadSection ( Section section)

在文件 record_file_reader.cc117 行定义.

117 {
118 ssize_t count = read(fd_, section, sizeof(struct Section));
119 if (count < 0) {
120 AERROR << "Read fd failed, fd_: " << fd_ << ", errno: " << errno;
121 return false;
122 } else if (count == 0) {
123 end_of_file_ = true;
124 AINFO << "Reach end of file.";
125 return false;
126 } else if (count != sizeof(struct Section)) {
127 AERROR << "Read fd failed, fd_: " << fd_
128 << ", expect count: " << sizeof(struct Section)
129 << ", actual count: " << count;
130 return false;
131 }
132 return true;
133}
#define AINFO
Definition log.h:42

◆ Reset()

bool apollo::cyber::record::RecordFileReader::Reset ( )

在文件 record_file_reader.cc55 行定义.

55 {
56 if (!SetPosition(sizeof(struct Section) + HEADER_LENGTH)) {
57 AERROR << "Reset position fail, file: " << path_;
58 return false;
59 }
60 end_of_file_ = false;
61 return true;
62}

◆ SkipSection()

bool apollo::cyber::record::RecordFileReader::SkipSection ( int64_t  size)

在文件 record_file_reader.cc135 行定义.

135 {
136 int64_t pos = CurrentPosition();
137 if (size > INT64_MAX - pos) {
138 AERROR << "Current position plus skip count is larger than INT64_MAX, "
139 << pos << " + " << size << " > " << INT64_MAX;
140 return false;
141 }
142 if (!SetPosition(pos + size)) {
143 AERROR << "Skip failed, file: " << path_ << ", current position: " << pos
144 << "skip count: " << size;
145 return false;
146 }
147 return true;
148}

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