17 #ifndef CYBER_RECORD_RECORD_WRITER_H_ 18 #define CYBER_RECORD_RECORD_WRITER_H_ 26 #include <unordered_map> 28 #include "cyber/proto/record.pb.h" 75 bool Open(
const std::string& file);
92 const std::string& message_type,
93 const std::string& proto_desc);
106 template <
typename MessageT>
107 bool WriteMessage(
const std::string& channel_name,
const MessageT& message,
108 const uint64_t time_nanosec,
109 const std::string& proto_desc =
"");
146 const std::string& channel_name)
const override;
156 const std::string& channel_name)
const override;
170 bool IsNewChannel(
const std::string& channel_name)
const;
173 bool WriteMessage(
const proto::SingleMessage& single_msg);
175 void OnNewChannel(
const std::string& channel_name,
176 const std::string& message_type,
177 const std::string& proto_desc);
178 void OnNewMessage(
const std::string& channel_name);
181 uint64_t segment_raw_size_ = 0;
182 uint64_t segment_begin_time_ = 0;
183 uint32_t file_index_ = 0;
190 std::stringstream sstream_;
195 const std::string& message,
196 const uint64_t time_nanosec,
197 const std::string& proto_desc) {
198 proto::SingleMessage single_msg;
199 single_msg.set_channel_name(channel_name);
200 single_msg.set_content(message);
201 single_msg.set_time(time_nanosec);
207 const std::string& channel_name,
208 const std::shared_ptr<message::RawMessage>& message,
209 const uint64_t time_nanosec,
const std::string& proto_desc) {
210 if (message ==
nullptr) {
211 AERROR <<
"nullptr error, channel: " << channel_name;
214 return WriteMessage(channel_name, message->message, time_nanosec);
217 template <
typename MessageT>
219 const MessageT& message,
220 const uint64_t time_nanosec,
221 const std::string& proto_desc) {
223 if (message_type.empty()) {
224 if (!
WriteChannel(channel_name, message::GetMessageName<MessageT>(),
226 AERROR <<
"Failed to write meta data to channel [" << channel_name
231 if (MessageT::descriptor()->full_name() != message_type) {
232 AERROR <<
"Message type is invalid, expect: " << message_type
233 <<
", actual: " << message::GetMessageName<MessageT>();
237 std::string content(
"");
238 if (!message.SerializeToString(&content)) {
239 AERROR <<
"Failed to serialize message, channel: " << channel_name;
242 return WriteMessage(channel_name, content, time_nanosec);
249 #endif // CYBER_RECORD_RECORD_WRITER_H_
std::unordered_map< std::string, std::string > MessageProtoDescMap
Definition: record_writer.h:48
bool WriteChannel(const std::string &channel_name, const std::string &message_type, const std::string &proto_desc)
Write a channel to record.
RecordWriter()
The default constructor.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
The record writer.
Definition: record_writer.h:44
bool SetIntervalOfFileSegmentation(uint64_t time_sec)
Set max interval (Second) to segment record file.
bool SetSizeOfFileSegmentation(uint64_t size_kilobytes)
Set max size (KB) to segment record file.
const std::string & GetProtoDesc(const std::string &channel_name) const override
Get proto descriptor string by channel name.
std::unique_ptr< RecordFileWriter > FileWriterPtr
Definition: record_writer.h:49
Base class for record reader and writer.
Definition: record_base.h:35
std::unordered_map< std::string, uint64_t > MessageNumberMap
Definition: record_writer.h:46
bool WriteMessage(const std::string &channel_name, const MessageT &message, const uint64_t time_nanosec, const std::string &proto_desc="")
Write a message to record.
Definition: record_writer.h:218
bool IsNewChannel(const std::string &channel_name) const
Is a new channel recording or not.
const std::string & GetMessageType(const std::string &channel_name) const override
Get message type by channel name.
void Close()
Clean the record.
virtual ~RecordWriter()
Virtual Destructor.
bool Open(const std::string &file)
Open a record to write.
uint64_t GetMessageNumber(const std::string &channel_name) const override
Get message number by channel name.
#define AERROR
Definition: log.h:44
std::set< std::string > GetChannelList() const override
Get channel list.
std::unordered_map< std::string, std::string > MessageTypeMap
Definition: record_writer.h:47