Move store/parse inside classes Invoice/InputInvoice.

This commit is contained in:
levlam 2022-09-24 23:00:49 +03:00
parent bb69175aab
commit ecb3d76fb4
2 changed files with 79 additions and 63 deletions

View File

@ -41,6 +41,12 @@ struct Invoice {
Invoice(string &&currency, bool is_test, bool need_shipping_address)
: currency_(std::move(currency)), is_test_(is_test), need_shipping_address_(need_shipping_address) {
}
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
struct InputInvoice {
@ -105,6 +111,12 @@ struct InputInvoice {
DialogId owner_dialog_id, Td *td);
bool need_poll_extended_media() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const InputInvoice &lhs, const InputInvoice &rhs);

View File

@ -17,70 +17,73 @@
namespace td {
template <class StorerT>
void store(const Invoice &invoice, StorerT &storer) {
bool has_tip = invoice.max_tip_amount_ != 0;
bool is_recurring = !invoice.recurring_payment_terms_of_service_url_.empty();
void Invoice::store(StorerT &storer) const {
using td::store;
bool has_tip = max_tip_amount_ != 0;
bool is_recurring = !recurring_payment_terms_of_service_url_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(invoice.is_test_);
STORE_FLAG(invoice.need_name_);
STORE_FLAG(invoice.need_phone_number_);
STORE_FLAG(invoice.need_email_address_);
STORE_FLAG(invoice.need_shipping_address_);
STORE_FLAG(invoice.is_flexible_);
STORE_FLAG(invoice.send_phone_number_to_provider_);
STORE_FLAG(invoice.send_email_address_to_provider_);
STORE_FLAG(is_test_);
STORE_FLAG(need_name_);
STORE_FLAG(need_phone_number_);
STORE_FLAG(need_email_address_);
STORE_FLAG(need_shipping_address_);
STORE_FLAG(is_flexible_);
STORE_FLAG(send_phone_number_to_provider_);
STORE_FLAG(send_email_address_to_provider_);
STORE_FLAG(has_tip);
STORE_FLAG(is_recurring);
END_STORE_FLAGS();
store(invoice.currency_, storer);
store(invoice.price_parts_, storer);
store(currency_, storer);
store(price_parts_, storer);
if (has_tip) {
store(invoice.max_tip_amount_, storer);
store(invoice.suggested_tip_amounts_, storer);
store(max_tip_amount_, storer);
store(suggested_tip_amounts_, storer);
}
if (is_recurring) {
store(invoice.recurring_payment_terms_of_service_url_, storer);
store(recurring_payment_terms_of_service_url_, storer);
}
}
template <class ParserT>
void parse(Invoice &invoice, ParserT &parser) {
void Invoice::parse(ParserT &parser) {
using td::parse;
bool has_tip;
bool is_recurring;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(invoice.is_test_);
PARSE_FLAG(invoice.need_name_);
PARSE_FLAG(invoice.need_phone_number_);
PARSE_FLAG(invoice.need_email_address_);
PARSE_FLAG(invoice.need_shipping_address_);
PARSE_FLAG(invoice.is_flexible_);
PARSE_FLAG(invoice.send_phone_number_to_provider_);
PARSE_FLAG(invoice.send_email_address_to_provider_);
PARSE_FLAG(is_test_);
PARSE_FLAG(need_name_);
PARSE_FLAG(need_phone_number_);
PARSE_FLAG(need_email_address_);
PARSE_FLAG(need_shipping_address_);
PARSE_FLAG(is_flexible_);
PARSE_FLAG(send_phone_number_to_provider_);
PARSE_FLAG(send_email_address_to_provider_);
PARSE_FLAG(has_tip);
PARSE_FLAG(is_recurring);
END_PARSE_FLAGS();
parse(invoice.currency_, parser);
parse(invoice.price_parts_, parser);
parse(currency_, parser);
parse(price_parts_, parser);
if (has_tip) {
parse(invoice.max_tip_amount_, parser);
parse(invoice.suggested_tip_amounts_, parser);
parse(max_tip_amount_, parser);
parse(suggested_tip_amounts_, parser);
}
if (is_recurring) {
parse(invoice.recurring_payment_terms_of_service_url_, parser);
parse(recurring_payment_terms_of_service_url_, parser);
}
}
template <class StorerT>
void store(const InputInvoice &input_invoice, StorerT &storer) {
bool has_description = !input_invoice.description_.empty();
bool has_photo = !input_invoice.photo_.is_empty();
bool has_start_parameter = !input_invoice.start_parameter_.empty();
bool has_payload = !input_invoice.payload_.empty();
bool has_provider_token = !input_invoice.provider_token_.empty();
bool has_provider_data = !input_invoice.provider_data_.empty();
bool has_total_amount = input_invoice.total_amount_ != 0;
bool has_receipt_message_id = input_invoice.receipt_message_id_.is_valid();
bool has_extended_media = !input_invoice.extended_media_.is_empty();
void InputInvoice::store(StorerT &storer) const {
using td::store;
bool has_description = !description_.empty();
bool has_photo = !photo_.is_empty();
bool has_start_parameter = !start_parameter_.empty();
bool has_payload = !payload_.empty();
bool has_provider_token = !provider_token_.empty();
bool has_provider_data = !provider_data_.empty();
bool has_total_amount = total_amount_ != 0;
bool has_receipt_message_id = receipt_message_id_.is_valid();
bool has_extended_media = !extended_media_.is_empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_description);
STORE_FLAG(has_photo);
@ -92,39 +95,40 @@ void store(const InputInvoice &input_invoice, StorerT &storer) {
STORE_FLAG(has_receipt_message_id);
STORE_FLAG(has_extended_media);
END_STORE_FLAGS();
store(input_invoice.title_, storer);
store(title_, storer);
if (has_description) {
store(input_invoice.description_, storer);
store(description_, storer);
}
if (has_photo) {
store(input_invoice.photo_, storer);
store(photo_, storer);
}
if (has_start_parameter) {
store(input_invoice.start_parameter_, storer);
store(start_parameter_, storer);
}
store(input_invoice.invoice_, storer);
store(invoice_, storer);
if (has_payload) {
store(input_invoice.payload_, storer);
store(payload_, storer);
}
if (has_provider_token) {
store(input_invoice.provider_token_, storer);
store(provider_token_, storer);
}
if (has_provider_data) {
store(input_invoice.provider_data_, storer);
store(provider_data_, storer);
}
if (has_total_amount) {
store(input_invoice.total_amount_, storer);
store(total_amount_, storer);
}
if (has_receipt_message_id) {
store(input_invoice.receipt_message_id_, storer);
store(receipt_message_id_, storer);
}
if (has_extended_media) {
store(input_invoice.extended_media_, storer);
store(extended_media_, storer);
}
}
template <class ParserT>
void parse(InputInvoice &input_invoice, ParserT &parser) {
void InputInvoice::parse(ParserT &parser) {
using td::parse;
bool has_description;
bool has_photo;
bool has_start_parameter;
@ -157,34 +161,34 @@ void parse(InputInvoice &input_invoice, ParserT &parser) {
has_receipt_message_id = true;
has_extended_media = false;
}
parse(input_invoice.title_, parser);
parse(title_, parser);
if (has_description) {
parse(input_invoice.description_, parser);
parse(description_, parser);
}
if (has_photo) {
parse(input_invoice.photo_, parser);
parse(photo_, parser);
}
if (has_start_parameter) {
parse(input_invoice.start_parameter_, parser);
parse(start_parameter_, parser);
}
parse(input_invoice.invoice_, parser);
parse(invoice_, parser);
if (has_payload) {
parse(input_invoice.payload_, parser);
parse(payload_, parser);
}
if (has_provider_token) {
parse(input_invoice.provider_token_, parser);
parse(provider_token_, parser);
}
if (has_provider_data) {
parse(input_invoice.provider_data_, parser);
parse(provider_data_, parser);
}
if (has_total_amount) {
parse(input_invoice.total_amount_, parser);
parse(total_amount_, parser);
}
if (has_receipt_message_id) {
parse(input_invoice.receipt_message_id_, parser);
parse(receipt_message_id_, parser);
}
if (has_extended_media) {
parse(input_invoice.extended_media_, parser);
parse(extended_media_, parser);
}
}