Add storer and parser for unique_ptr.

GitOrigin-RevId: 2b0f5c8a3e9f7a9343cf9557d10cbf95009ba847
This commit is contained in:
levlam 2019-09-18 02:42:38 +03:00
parent ae574ceebc
commit 15f31cf23a
6 changed files with 29 additions and 34 deletions

View File

@ -2679,7 +2679,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
STORE_FLAG(has_private_calls);
END_STORE_FLAGS();
if (has_bot_info) {
store(*bot_info, storer);
store(bot_info, storer);
}
if (has_about) {
store(about, storer);
@ -2702,8 +2702,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
PARSE_FLAG(has_private_calls);
END_PARSE_FLAGS();
if (has_bot_info) {
bot_info = make_unique<BotInfo>();
parse(*bot_info, parser);
parse(bot_info, parser);
}
if (has_about) {
parse(about, parser);

View File

@ -942,7 +942,7 @@ static void store(const MessageContent *content, StorerT &storer) {
store(m->invoice_payload, storer);
}
if (has_order_info) {
store(*m->order_info, storer);
store(m->order_info, storer);
}
if (has_telegram_payment_charge_id) {
store(m->telegram_payment_charge_id, storer);
@ -1274,8 +1274,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
parse(m->invoice_payload, parser);
}
if (has_order_info) {
m->order_info = make_unique<OrderInfo>();
parse(*m->order_info, parser);
parse(m->order_info, parser);
}
if (has_telegram_payment_charge_id) {
parse(m->telegram_payment_charge_id, parser);

View File

@ -3858,7 +3858,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
}
store_message_content(content.get(), storer);
if (has_reply_markup) {
store(*reply_markup, storer);
store(reply_markup, storer);
}
}
@ -4009,8 +4009,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
}
parse_message_content(content, parser);
if (has_reply_markup) {
reply_markup = make_unique<ReplyMarkup>();
parse(*reply_markup, parser);
parse(reply_markup, parser);
}
is_content_secret |=
is_secret_message_content(ttl, content->get_type()); // repair is_content_secret for old messages
@ -4125,7 +4124,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
store(reply_markup_message_id, storer);
store(notification_settings, storer);
if (has_draft_message) {
store(*draft_message, storer);
store(draft_message, storer);
}
store(last_clear_history_date, storer);
store(order, storer);
@ -4284,14 +4283,12 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
parse(reply_markup_message_id, parser);
parse(notification_settings, parser);
if (has_draft_message) {
draft_message = make_unique<DraftMessage>();
parse(*draft_message, parser);
parse(draft_message, parser);
}
parse(last_clear_history_date, parser);
parse(order, parser);
if (has_last_database_message) {
messages = make_unique<Message>();
parse(*messages, parser);
parse(messages, parser);
}
if (has_first_database_message_id) {
parse(first_database_message_id, parser);
@ -16779,9 +16776,7 @@ class MessagesManager::SendMessageLogEvent {
template <class ParserT>
void parse(ParserT &parser) {
td::parse(dialog_id, parser);
CHECK(m_out == nullptr);
m_out = make_unique<Message>();
td::parse(*m_out, parser);
td::parse(m_out, parser);
}
};
@ -17586,9 +17581,7 @@ class MessagesManager::SendBotStartMessageLogEvent {
td::parse(bot_user_id, parser);
td::parse(dialog_id, parser);
td::parse(parameter, parser);
CHECK(m_out == nullptr);
m_out = make_unique<Message>();
td::parse(*m_out, parser);
td::parse(m_out, parser);
}
};
@ -17725,9 +17718,7 @@ class MessagesManager::SendInlineQueryResultMessageLogEvent {
td::parse(dialog_id, parser);
td::parse(query_id, parser);
td::parse(result_id, parser);
CHECK(m_out == nullptr);
m_out = make_unique<Message>();
td::parse(*m_out, parser);
td::parse(m_out, parser);
}
};
@ -18943,8 +18934,7 @@ class MessagesManager::ForwardMessagesLogEvent {
int32 size = parser.fetch_int();
messages_out.resize(size);
for (auto &m_out : messages_out) {
m_out = make_unique<Message>();
td::parse(*m_out, parser);
td::parse(m_out, parser);
}
}
};
@ -19445,9 +19435,7 @@ class MessagesManager::SendScreenshotTakenNotificationMessageLogEvent {
template <class ParserT>
void parse(ParserT &parser) {
td::parse(dialog_id, parser);
CHECK(m_out == nullptr);
m_out = make_unique<Message>();
td::parse(*m_out, parser);
td::parse(m_out, parser);
}
};

View File

@ -100,7 +100,7 @@ void store(const OrderInfo &order_info, StorerT &storer) {
store(order_info.email_address, storer);
}
if (has_shipping_address) {
store(*order_info.shipping_address, storer);
store(order_info.shipping_address, storer);
}
}
@ -126,8 +126,7 @@ void parse(OrderInfo &order_info, ParserT &parser) {
parse(order_info.email_address, parser);
}
if (has_shipping_address) {
order_info.shipping_address = make_unique<Address>();
parse(*order_info.shipping_address, parser);
parse(order_info.shipping_address, parser);
}
}

View File

@ -1299,9 +1299,7 @@ class WebPagesManager::WebPageLogEvent {
template <class ParserT>
void parse(ParserT &parser) {
td::parse(web_page_id, parser);
CHECK(web_page_out == nullptr);
web_page_out = make_unique<WebPage>();
td::parse(*web_page_out, parser);
td::parse(web_page_out, parser);
}
};

View File

@ -151,6 +151,18 @@ void parse(vector<T> &vec, ParserT &parser) {
}
}
template <class T, class StorerT>
void store(const unique_ptr<T> &ptr, StorerT &storer) {
CHECK(ptr != nullptr);
store(*ptr, storer);
}
template <class T, class ParserT>
void parse(unique_ptr<T> &ptr, ParserT &parser) {
CHECK(ptr == nullptr);
ptr = make_unique<T>();
parse(*ptr, parser);
}
template <class Key, class Hash, class KeyEqual, class Allocator, class StorerT>
void store(const std::unordered_set<Key, Hash, KeyEqual, Allocator> &s, StorerT &storer) {
storer.store_binary(narrow_cast<int32>(s.size()));