blob: 6b55e518ba5313b81f3edf428ed474b70c37b0cf [file] [log] [blame]
Brian Silvermancb5da1f2015-12-05 22:19:58 -05001#include "aos/common/logging/replay.h"
Brian Silvermand0575692015-02-21 16:24:02 -05002
Austin Schuhf2a50ba2016-12-24 16:16:26 -08003#include <chrono>
4
Brian Silvermand0575692015-02-21 16:24:02 -05005namespace aos {
6namespace logging {
7namespace linux_code {
8
Austin Schuhf2a50ba2016-12-24 16:16:26 -08009namespace chrono = ::std::chrono;
10
Brian Silvermand0575692015-02-21 16:24:02 -050011bool LogReplayer::ProcessMessage() {
12 const LogFileMessageHeader *message = reader_->ReadNextMessage(false);
13 if (message == nullptr) return true;
14 if (message->type != LogFileMessageHeader::MessageType::kStruct) return false;
15
16 const char *position = reinterpret_cast<const char *>(message + 1);
17
18 ::std::string process(position, message->name_size);
19 position += message->name_size;
20
21 uint32_t type_id;
22 memcpy(&type_id, position, sizeof(type_id));
23 position += sizeof(type_id);
24
25 uint32_t message_length;
26 memcpy(&message_length, position, sizeof(message_length));
27 position += sizeof(message_length);
28 ::std::string message_text(position, message_length);
29 position += message_length;
30
31 size_t split_index = message_text.find_first_of(':') + 2;
32 split_index = message_text.find_first_of(':', split_index) + 2;
33 message_text = message_text.substr(split_index);
34
35 auto handler = handlers_.find(Key(process, message_text));
36 if (handler == handlers_.end()) return false;
37
38 handler->second->HandleStruct(
Austin Schuhf2a50ba2016-12-24 16:16:26 -080039 monotonic_clock::time_point(chrono::seconds(message->time_sec) +
40 chrono::nanoseconds(message->time_nsec)),
41 type_id, position,
Brian Silvermand0575692015-02-21 16:24:02 -050042 message->message_size -
43 (sizeof(type_id) + sizeof(message_length) + message_length));
44 return false;
45}
46
47} // namespace linux_code
48} // namespace logging
49} // namespace aos