blob: 32991de68a1dc578aaf9c3df404d464f5618b488 [file] [log] [blame]
Brian Silvermand0575692015-02-21 16:24:02 -05001#include "aos/linux_code/logging/log_replay.h"
2
3namespace aos {
4namespace logging {
5namespace linux_code {
6
7bool LogReplayer::ProcessMessage() {
8 const LogFileMessageHeader *message = reader_->ReadNextMessage(false);
9 if (message == nullptr) return true;
10 if (message->type != LogFileMessageHeader::MessageType::kStruct) return false;
11
12 const char *position = reinterpret_cast<const char *>(message + 1);
13
14 ::std::string process(position, message->name_size);
15 position += message->name_size;
16
17 uint32_t type_id;
18 memcpy(&type_id, position, sizeof(type_id));
19 position += sizeof(type_id);
20
21 uint32_t message_length;
22 memcpy(&message_length, position, sizeof(message_length));
23 position += sizeof(message_length);
24 ::std::string message_text(position, message_length);
25 position += message_length;
26
27 size_t split_index = message_text.find_first_of(':') + 2;
28 split_index = message_text.find_first_of(':', split_index) + 2;
29 message_text = message_text.substr(split_index);
30
31 auto handler = handlers_.find(Key(process, message_text));
32 if (handler == handlers_.end()) return false;
33
34 handler->second->HandleStruct(
35 ::aos::time::Time(message->time_sec, message->time_nsec), type_id,
36 position,
37 message->message_size -
38 (sizeof(type_id) + sizeof(message_length) + message_length));
39 return false;
40}
41
42} // namespace linux_code
43} // namespace logging
44} // namespace aos