Replace unsafe to maintain data_ field with get_data() method.

This commit is contained in:
levlam 2023-02-02 03:08:26 +03:00
parent 2a5f6121ef
commit 882de6e8e8
15 changed files with 67 additions and 66 deletions

View File

@ -127,7 +127,7 @@ void on_save_app_log_binlog_event(Td *td, BinlogEvent &&event) {
CHECK(event.id_ != 0); CHECK(event.id_ != 0);
CHECK(event.type_ == LogEvent::HandlerType::SaveAppLog); CHECK(event.type_ == LogEvent::HandlerType::SaveAppLog);
SaveAppLogLogEvent log_event; SaveAppLogLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
save_app_log_impl(td, std::move(log_event.input_app_event_out_), event.id_, Promise<Unit>()); save_app_log_impl(td, std::move(log_event.input_app_event_out_), event.id_, Promise<Unit>());
} }

View File

@ -9979,7 +9979,7 @@ void ContactsManager::on_binlog_user_event(BinlogEvent &&event) {
} }
UserLogEvent log_event; UserLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto user_id = log_event.user_id; auto user_id = log_event.user_id;
if (have_min_user(user_id) || !user_id.is_valid()) { if (have_min_user(user_id) || !user_id.is_valid()) {
@ -10303,7 +10303,7 @@ void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) {
} }
ChatLogEvent log_event; ChatLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto chat_id = log_event.chat_id; auto chat_id = log_event.chat_id;
if (have_chat(chat_id) || !chat_id.is_valid()) { if (have_chat(chat_id) || !chat_id.is_valid()) {
@ -10542,7 +10542,7 @@ void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) {
} }
ChannelLogEvent log_event; ChannelLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto channel_id = log_event.channel_id; auto channel_id = log_event.channel_id;
if (have_channel(channel_id) || !channel_id.is_valid()) { if (have_channel(channel_id) || !channel_id.is_valid()) {
@ -10797,7 +10797,7 @@ void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) {
} }
SecretChatLogEvent log_event; SecretChatLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto secret_chat_id = log_event.secret_chat_id; auto secret_chat_id = log_event.secret_chat_id;
if (have_secret_chat(secret_chat_id) || !secret_chat_id.is_valid()) { if (have_secret_chat(secret_chat_id) || !secret_chat_id.is_valid()) {

View File

@ -40415,14 +40415,14 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SendMessageLogEvent log_event; SendMessageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id; auto dialog_id = log_event.dialog_id;
auto m = std::move(log_event.m_out); auto m = std::move(log_event.m_out);
m->send_message_log_event_id = event.id_; m->send_message_log_event_id = event.id_;
if (m->content->get_type() == MessageContentType::Unsupported) { if (m->content->get_type() == MessageContentType::Unsupported) {
LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(event.get_data());
binlog_erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
@ -40456,7 +40456,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SendBotStartMessageLogEvent log_event; SendBotStartMessageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id; auto dialog_id = log_event.dialog_id;
auto m = std::move(log_event.m_out); auto m = std::move(log_event.m_out);
@ -40496,14 +40496,14 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SendInlineQueryResultMessageLogEvent log_event; SendInlineQueryResultMessageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id; auto dialog_id = log_event.dialog_id;
auto m = std::move(log_event.m_out); auto m = std::move(log_event.m_out);
m->send_message_log_event_id = event.id_; m->send_message_log_event_id = event.id_;
if (m->content->get_type() == MessageContentType::Unsupported) { if (m->content->get_type() == MessageContentType::Unsupported) {
LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(event.get_data());
binlog_erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
@ -40536,7 +40536,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SendScreenshotTakenNotificationMessageLogEvent log_event; SendScreenshotTakenNotificationMessageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id; auto dialog_id = log_event.dialog_id;
auto m = std::move(log_event.m_out); auto m = std::move(log_event.m_out);
@ -40569,7 +40569,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ForwardMessagesLogEvent log_event; ForwardMessagesLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto to_dialog_id = log_event.to_dialog_id; auto to_dialog_id = log_event.to_dialog_id;
auto from_dialog_id = log_event.from_dialog_id; auto from_dialog_id = log_event.from_dialog_id;
@ -40649,7 +40649,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteMessageLogEvent log_event; DeleteMessageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
log_event.id_ = event.id_; log_event.id_ = event.id_;
Dialog *d = get_dialog_force(log_event.full_message_id_.get_dialog_id(), "DeleteMessageLogEvent"); Dialog *d = get_dialog_force(log_event.full_message_id_.get_dialog_id(), "DeleteMessageLogEvent");
@ -40672,7 +40672,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteMessagesOnServerLogEvent log_event; DeleteMessagesOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "DeleteMessagesOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "DeleteMessagesOnServerLogEvent");
@ -40696,7 +40696,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteScheduledMessagesOnServerLogEvent log_event; DeleteScheduledMessagesOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "DeleteScheduledMessagesOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "DeleteScheduledMessagesOnServerLogEvent");
@ -40720,7 +40720,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteDialogHistoryOnServerLogEvent log_event; DeleteDialogHistoryOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "DeleteDialogHistoryOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "DeleteDialogHistoryOnServerLogEvent");
@ -40740,7 +40740,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteTopicHistoryOnServerLogEvent log_event; DeleteTopicHistoryOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "DeleteTopicHistoryOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "DeleteTopicHistoryOnServerLogEvent");
@ -40754,14 +40754,14 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::DeleteAllCallMessagesOnServer: { case LogEvent::HandlerType::DeleteAllCallMessagesOnServer: {
DeleteAllCallMessagesOnServerLogEvent log_event; DeleteAllCallMessagesOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
delete_all_call_messages_on_server(log_event.revoke_, event.id_, Auto()); delete_all_call_messages_on_server(log_event.revoke_, event.id_, Auto());
break; break;
} }
case LogEvent::HandlerType::BlockMessageSenderFromRepliesOnServer: { case LogEvent::HandlerType::BlockMessageSenderFromRepliesOnServer: {
BlockMessageSenderFromRepliesOnServerLogEvent log_event; BlockMessageSenderFromRepliesOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
block_message_sender_from_replies_on_server(log_event.message_id_, log_event.delete_message_, block_message_sender_from_replies_on_server(log_event.message_id_, log_event.delete_message_,
log_event.delete_all_messages_, log_event.report_spam_, event.id_, log_event.delete_all_messages_, log_event.report_spam_, event.id_,
@ -40775,7 +40775,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteAllChannelMessagesFromSenderOnServerLogEvent log_event; DeleteAllChannelMessagesFromSenderOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto channel_id = log_event.channel_id_; auto channel_id = log_event.channel_id_;
if (!td_->contacts_manager_->have_channel_force(channel_id)) { if (!td_->contacts_manager_->have_channel_force(channel_id)) {
@ -40801,7 +40801,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
DeleteDialogMessagesByDateOnServerLogEvent log_event; DeleteDialogMessagesByDateOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "DeleteDialogMessagesByDateOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "DeleteDialogMessagesByDateOnServerLogEvent");
@ -40821,7 +40821,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReadHistoryOnServerLogEvent log_event; ReadHistoryOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ReadHistoryOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ReadHistoryOnServerLogEvent");
@ -40840,7 +40840,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ReadHistoryInSecretChat: { case LogEvent::HandlerType::ReadHistoryInSecretChat: {
ReadHistoryInSecretChatLogEvent log_event; ReadHistoryInSecretChatLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
CHECK(dialog_id.get_type() == DialogType::SecretChat); CHECK(dialog_id.get_type() == DialogType::SecretChat);
@ -40872,7 +40872,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReadMessageThreadHistoryOnServerLogEvent log_event; ReadMessageThreadHistoryOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ReadMessageThreadHistoryOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ReadMessageThreadHistoryOnServerLogEvent");
@ -40898,7 +40898,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReadMessageContentsOnServerLogEvent log_event; ReadMessageContentsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ReadMessageContentsOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ReadMessageContentsOnServerLogEvent");
@ -40917,7 +40917,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReadAllDialogMentionsOnServerLogEvent log_event; ReadAllDialogMentionsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ReadAllDialogMentionsOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ReadAllDialogMentionsOnServerLogEvent");
@ -40936,7 +40936,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReadAllDialogReactionsOnServerLogEvent log_event; ReadAllDialogReactionsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ReadAllDialogReactionsOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ReadAllDialogReactionsOnServerLogEvent");
@ -40955,7 +40955,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ToggleDialogIsPinnedOnServerLogEvent log_event; ToggleDialogIsPinnedOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ToggleDialogIsPinnedOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ToggleDialogIsPinnedOnServerLogEvent");
@ -40974,7 +40974,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ReorderPinnedDialogsOnServerLogEvent log_event; ReorderPinnedDialogsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
vector<DialogId> dialog_ids; vector<DialogId> dialog_ids;
for (auto &dialog_id : log_event.dialog_ids_) { for (auto &dialog_id : log_event.dialog_ids_) {
@ -40998,7 +40998,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ToggleDialogIsMarkedAsUnreadOnServerLogEvent log_event; ToggleDialogIsMarkedAsUnreadOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
bool have_info = dialog_id.get_type() == DialogType::User bool have_info = dialog_id.get_type() == DialogType::User
@ -41019,7 +41019,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ToggleDialogIsBlockedOnServerLogEvent log_event; ToggleDialogIsBlockedOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
if (dialog_id.get_type() == DialogType::SecretChat || !have_dialog_info_force(dialog_id) || if (dialog_id.get_type() == DialogType::SecretChat || !have_dialog_info_force(dialog_id) ||
@ -41038,7 +41038,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SaveDialogDraftMessageOnServerLogEvent log_event; SaveDialogDraftMessageOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "SaveDialogDraftMessageOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "SaveDialogDraftMessageOnServerLogEvent");
@ -41058,7 +41058,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
UpdateDialogNotificationSettingsOnServerLogEvent log_event; UpdateDialogNotificationSettingsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "UpdateDialogNotificationSettingsOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "UpdateDialogNotificationSettingsOnServerLogEvent");
@ -41073,7 +41073,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ResetAllNotificationSettingsOnServer: { case LogEvent::HandlerType::ResetAllNotificationSettingsOnServer: {
ResetAllNotificationSettingsOnServerLogEvent log_event; ResetAllNotificationSettingsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
reset_all_notification_settings_on_server(event.id_); reset_all_notification_settings_on_server(event.id_);
break; break;
@ -41085,7 +41085,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
ToggleDialogReportSpamStateOnServerLogEvent log_event; ToggleDialogReportSpamStateOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "ToggleDialogReportSpamStateOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "ToggleDialogReportSpamStateOnServerLogEvent");
@ -41104,7 +41104,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SetDialogFolderIdOnServerLogEvent log_event; SetDialogFolderIdOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id, "SetDialogFolderIdOnServerLogEvent"); Dialog *d = get_dialog_force(dialog_id, "SetDialogFolderIdOnServerLogEvent");
@ -41126,7 +41126,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
RegetDialogLogEvent log_event; RegetDialogLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dependencies dependencies; Dependencies dependencies;
@ -41150,7 +41150,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
UnpinAllDialogMessagesOnServerLogEvent log_event; UnpinAllDialogMessagesOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
unpin_all_dialog_messages_on_server(log_event.dialog_id_, event.id_, Auto()); unpin_all_dialog_messages_on_server(log_event.dialog_id_, event.id_, Auto());
break; break;
@ -41162,7 +41162,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
GetChannelDifferenceLogEvent log_event; GetChannelDifferenceLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
DialogId dialog_id(log_event.channel_id); DialogId dialog_id(log_event.channel_id);
if (dialog_id.get_type() != DialogType::Channel) { if (dialog_id.get_type() != DialogType::Channel) {

View File

@ -4186,7 +4186,7 @@ void NotificationManager::on_binlog_events(vector<BinlogEvent> &&events) {
case LogEvent::HandlerType::AddMessagePushNotification: { case LogEvent::HandlerType::AddMessagePushNotification: {
CHECK(is_inited_); CHECK(is_inited_);
AddMessagePushNotificationLogEvent log_event; AddMessagePushNotificationLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
add_message_push_notification( add_message_push_notification(
log_event.dialog_id_, log_event.message_id_, log_event.random_id_, log_event.sender_user_id_, log_event.dialog_id_, log_event.message_id_, log_event.random_id_, log_event.sender_user_id_,
@ -4203,7 +4203,7 @@ void NotificationManager::on_binlog_events(vector<BinlogEvent> &&events) {
case LogEvent::HandlerType::EditMessagePushNotification: { case LogEvent::HandlerType::EditMessagePushNotification: {
CHECK(is_inited_); CHECK(is_inited_);
EditMessagePushNotificationLogEvent log_event; EditMessagePushNotificationLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
edit_message_push_notification( edit_message_push_notification(
log_event.dialog_id_, log_event.message_id_, log_event.edit_date_, log_event.loc_key_, log_event.arg_, log_event.dialog_id_, log_event.message_id_, log_event.edit_date_, log_event.loc_key_, log_event.arg_,

View File

@ -1493,7 +1493,7 @@ void NotificationSettingsManager::on_binlog_events(vector<BinlogEvent> &&events)
switch (event.type_) { switch (event.type_) {
case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer: { case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer: {
UpdateScopeNotificationSettingsOnServerLogEvent log_event; UpdateScopeNotificationSettingsOnServerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
update_scope_notification_settings_on_server(log_event.scope_, event.id_); update_scope_notification_settings_on_server(log_event.scope_, event.id_);
break; break;

View File

@ -1822,7 +1822,7 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
SetPollAnswerLogEvent log_event; SetPollAnswerLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.full_message_id_.get_dialog_id(); auto dialog_id = log_event.full_message_id_.get_dialog_id();
@ -1841,7 +1841,7 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
StopPollLogEvent log_event; StopPollLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.full_message_id_.get_dialog_id(); auto dialog_id = log_event.full_message_id_.get_dialog_id();

View File

@ -1563,7 +1563,7 @@ void WebPagesManager::on_binlog_web_page_event(BinlogEvent &&event) {
} }
WebPageLogEvent log_event; WebPageLogEvent log_event;
log_event_parse(log_event, event.data_).ensure(); log_event_parse(log_event, event.get_data()).ensure();
auto web_page_id = log_event.web_page_id; auto web_page_id = log_event.web_page_id;
if (!web_page_id.is_valid()) { if (!web_page_id.is_valid()) {

View File

@ -82,7 +82,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
name, name,
[&](const BinlogEvent &binlog_event) { [&](const BinlogEvent &binlog_event) {
Event event; Event event;
event.parse(TlParser(binlog_event.data_)); event.parse(TlParser(binlog_event.get_data()));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
}, },
std::move(db_key), DbKey::empty(), scheduler_id)); std::move(db_key), DbKey::empty(), scheduler_id));
@ -103,7 +103,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
void external_init_handle(const BinlogEvent &binlog_event) { void external_init_handle(const BinlogEvent &binlog_event) {
Event event; Event event;
event.parse(TlParser(binlog_event.data_)); event.parse(TlParser(binlog_event.get_data()));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
} }

View File

@ -550,7 +550,7 @@ void TQueueBinlog<BinlogT>::pop(uint64 log_event_id) {
template <class BinlogT> template <class BinlogT>
Status TQueueBinlog<BinlogT>::replay(const BinlogEvent &binlog_event, TQueue &q) const { Status TQueueBinlog<BinlogT>::replay(const BinlogEvent &binlog_event, TQueue &q) const {
TQueueLogEvent event; TQueueLogEvent event;
TlParser parser(binlog_event.data_); TlParser parser(binlog_event.get_data());
int32 has_extra = binlog_event.type_ - BINLOG_EVENT_TYPE; int32 has_extra = binlog_event.type_ - BINLOG_EVENT_TYPE;
if (has_extra != 0 && has_extra != 1) { if (has_extra != 0 && has_extra != 1) {
return Status::Error("Wrong magic"); return Status::Error("Wrong magic");

View File

@ -345,7 +345,7 @@ void Binlog::do_event(BinlogEvent &&event) {
if (event.type_ < 0) { if (event.type_ < 0) {
if (event.type_ == BinlogEvent::ServiceTypes::AesCtrEncryption) { if (event.type_ == BinlogEvent::ServiceTypes::AesCtrEncryption) {
detail::AesCtrEncryptionEvent encryption_event; detail::AesCtrEncryptionEvent encryption_event;
encryption_event.parse(TlParser(event.data_)); encryption_event.parse(TlParser(event.get_data()));
string key; string key;
if (aes_ctr_key_salt_ == encryption_event.key_salt_) { if (aes_ctr_key_salt_ == encryption_event.key_salt_) {

View File

@ -23,8 +23,7 @@ Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
flags_ = parser.fetch_int(); flags_ = parser.fetch_int();
extra_ = parser.fetch_long(); extra_ = parser.fetch_long();
CHECK(size_ >= MIN_SIZE); CHECK(size_ >= MIN_SIZE);
auto slice_data = parser.fetch_string_raw<Slice>(size_ - MIN_SIZE); parser.fetch_string_raw<Slice>(size_ - MIN_SIZE); // skip data
data_ = MutableSlice(const_cast<char *>(slice_data.begin()), slice_data.size());
crc32_ = static_cast<uint32>(parser.fetch_int()); crc32_ = static_cast<uint32>(parser.fetch_int());
if (check_crc) { if (check_crc) {
auto calculated_crc = crc32(raw_event.as_slice().substr(0, size_ - TAIL_SIZE)); auto calculated_crc = crc32(raw_event.as_slice().substr(0, size_ - TAIL_SIZE));
@ -37,6 +36,10 @@ Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
return Status::OK(); return Status::OK();
} }
Slice BinlogEvent::get_data() const {
return Slice(raw_event_.as_slice().data() + HEADER_SIZE, size_ - MIN_SIZE);
}
Status BinlogEvent::validate() const { Status BinlogEvent::validate() const {
BinlogEvent event; BinlogEvent event;
if (raw_event_.size() < 4) { if (raw_event_.size() < 4) {
@ -69,10 +72,7 @@ BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const St
} }
void BinlogEvent::realloc() { void BinlogEvent::realloc() {
auto data_offset = data_.begin() - raw_event_.as_slice().begin();
auto data_size = data_.size();
raw_event_ = raw_event_.copy(); raw_event_ = raw_event_.copy();
data_ = raw_event_.as_slice().substr(data_offset, data_size);
} }
} // namespace td } // namespace td

View File

@ -60,7 +60,6 @@ struct BinlogEvent {
int32 type_; // type can be merged with flags int32 type_; // type can be merged with flags
int32 flags_; int32 flags_;
uint64 extra_; uint64 extra_;
MutableSlice data_;
uint32 crc32_; uint32 crc32_;
BufferSlice raw_event_; BufferSlice raw_event_;
@ -70,6 +69,8 @@ struct BinlogEvent {
enum ServiceTypes { Header = -1, Empty = -2, AesCtrEncryption = -3, NoEncryption = -4 }; enum ServiceTypes { Header = -1, Empty = -2, AesCtrEncryption = -3, NoEncryption = -4 };
enum Flags { Rewrite = 1, Partial = 2 }; enum Flags { Rewrite = 1, Partial = 2 };
Slice get_data() const;
void clear() { void clear() {
raw_event_ = BufferSlice(); raw_event_ = BufferSlice();
} }
@ -84,7 +85,7 @@ struct BinlogEvent {
} }
BufferSlice data_as_buffer_slice() const { BufferSlice data_as_buffer_slice() const {
return raw_event_.from_slice(data_); return raw_event_.from_slice(get_data());
} }
BinlogEvent() = default; BinlogEvent() = default;
@ -102,7 +103,7 @@ struct BinlogEvent {
std::string public_to_string() const { std::string public_to_string() const {
return PSTRING() << "LogEvent[" << tag("id", format::as_hex(id_)) << tag("type", type_) << tag("flags", flags_) return PSTRING() << "LogEvent[" << tag("id", format::as_hex(id_)) << tag("type", type_) << tag("flags", flags_)
<< tag("data", data_.size()) << "]" << debug_info_; << tag("data", get_data().size()) << "]" << debug_info_;
} }
Status validate() const; Status validate() const;
@ -112,7 +113,7 @@ struct BinlogEvent {
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) { inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {
return sb << "LogEvent[" << tag("id", format::as_hex(event.id_)) << tag("type", event.type_) return sb << "LogEvent[" << tag("id", format::as_hex(event.id_)) << tag("type", event.type_)
<< tag("flags", event.flags_) << tag("data", format::as_hex_dump<4>(event.data_)) << "]" << tag("flags", event.flags_) << tag("data", format::as_hex_dump<4>(event.get_data())) << "]"
<< event.debug_info_; << event.debug_info_;
} }

View File

@ -125,7 +125,7 @@ int main(int argc, char *argv[]) {
info[0].compressed_size += event.raw_event_.size(); info[0].compressed_size += event.raw_event_.size();
info[event.type_].compressed_size += event.raw_event_.size(); info[event.type_].compressed_size += event.raw_event_.size();
if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) { if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) {
auto key = td::TlParser(event.data_).fetch_string<td::Slice>(); auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>();
info[event.type_].compressed_trie.add(key); info[event.type_].compressed_trie.add(key);
} }
}, },
@ -134,13 +134,13 @@ int main(int argc, char *argv[]) {
info[0].full_size += event.raw_event_.size(); info[0].full_size += event.raw_event_.size();
info[event.type_].full_size += event.raw_event_.size(); info[event.type_].full_size += event.raw_event_.size();
if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) { if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) {
auto key = td::TlParser(event.data_).fetch_string<td::Slice>(); auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>();
info[event.type_].trie.add(key); info[event.type_].trie.add(key);
} }
LOG(PLAIN) << "LogEvent[" << td::tag("event_id", td::format::as_hex(event.id_)) LOG(PLAIN) << "LogEvent[" << td::tag("event_id", td::format::as_hex(event.id_))
<< td::tag("type", event.type_) << td::tag("flags", event.flags_) << td::tag("type", event.type_) << td::tag("flags", event.flags_)
<< td::tag("size", event.data_.size()) << td::tag("data", td::format::escaped(event.data_)) << td::tag("size", event.get_data().size())
<< "]\n"; << td::tag("data", td::format::escaped(event.get_data())) << "]\n";
}) })
.ensure(); .ensure();

View File

@ -25,7 +25,7 @@ class BinlogEventsBuffer {
auto &event = events_[i]; auto &event = events_[i];
if (i + 1 != ids_.size() && (event.flags_ & BinlogEvent::Flags::Partial) == 0) { if (i + 1 != ids_.size() && (event.flags_ & BinlogEvent::Flags::Partial) == 0) {
callback(BinlogEvent(BinlogEvent::create_raw(event.id_, event.type_, event.flags_ | BinlogEvent::Flags::Partial, callback(BinlogEvent(BinlogEvent::create_raw(event.id_, event.type_, event.flags_ | BinlogEvent::Flags::Partial,
create_storer(event.data_)), create_storer(event.get_data())),
BinlogDebugInfo{__FILE__, __LINE__})); BinlogDebugInfo{__FILE__, __LINE__}));
} else { } else {
callback(std::move(event)); callback(std::move(event));

View File

@ -105,7 +105,7 @@ TEST(DB, binlog_encryption) {
td::Binlog binlog; td::Binlog binlog;
binlog binlog
.init( .init(
binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.data_.str()); }, hello) binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.get_data().str()); }, hello)
.ensure(); .ensure();
CHECK(v == td::vector<td::string>({"AAAA", "BBBB", long_data, "CCCC"})); CHECK(v == td::vector<td::string>({"AAAA", "BBBB", long_data, "CCCC"}));
} }
@ -117,7 +117,7 @@ TEST(DB, binlog_encryption) {
LOG(INFO) << "RESTART"; LOG(INFO) << "RESTART";
td::Binlog binlog; td::Binlog binlog;
auto status = binlog.init( auto status = binlog.init(
binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber); binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.get_data().str()); }, cucumber);
CHECK(status.is_error()); CHECK(status.is_error());
} }
@ -128,7 +128,7 @@ TEST(DB, binlog_encryption) {
LOG(INFO) << "RESTART"; LOG(INFO) << "RESTART";
td::Binlog binlog; td::Binlog binlog;
auto status = binlog.init( auto status = binlog.init(
binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber, hello); binlog_name.str(), [&](const td::BinlogEvent &x) { v.push_back(x.get_data().str()); }, cucumber, hello);
CHECK(v == td::vector<td::string>({"AAAA", "BBBB", long_data, "CCCC"})); CHECK(v == td::vector<td::string>({"AAAA", "BBBB", long_data, "CCCC"}));
} }
} }