summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tgbot/EventBroadcaster.h6
-rw-r--r--include/tgbot/TgTypeParser.h4
-rw-r--r--include/tgbot/net/HttpParser.h8
-rw-r--r--include/tgbot/net/HttpServer.h4
-rw-r--r--include/tgbot/net/TgWebhookServer.h2
-rw-r--r--src/Api.cpp671
-rw-r--r--src/net/HttpParser.cpp2
-rw-r--r--test/tgbot/net/HttpParser.cpp8
8 files changed, 381 insertions, 324 deletions
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index 5a41c70..0a4ebe9 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -26,7 +26,7 @@
#include <string>
#include <functional>
#include <vector>
-#include <map>
+#include <unordered_map>
#include "tgbot/types/Message.h"
#include "tgbot/types/InlineQuery.h"
@@ -133,7 +133,7 @@ private:
}
inline bool broadcastCommand(const std::string command, const Message::Ptr message) const {
- std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
+ std::unordered_map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
if (iter == _onCommandListeners.end()) {
return false;
}
@@ -162,7 +162,7 @@ private:
}
std::vector<MessageListener> _onAnyMessageListeners;
- std::map<std::string, MessageListener> _onCommandListeners;
+ std::unordered_map<std::string, MessageListener> _onCommandListeners;
std::vector<MessageListener> _onUnknownCommandListeners;
std::vector<MessageListener> _onNonCommandMessageListeners;
std::vector<InlineQueryListener> _onInlineQueryListeners;
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index a24184a..6df9f36 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -314,6 +314,7 @@ public:
template<typename T>
std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data) const {
std::vector<std::shared_ptr<T>> result;
+ result.reserve(data.size());
for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : data) {
result.push_back((this->*parseFunc)(innerTreeItem.second));
}
@@ -327,6 +328,7 @@ public:
if (treeItem == data.not_found()) {
return result;
}
+ result.reserve(treeItem->second.size());
for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) {
result.push_back(parseFunc(innerTreeItem.second));
}
@@ -340,6 +342,7 @@ public:
if (treeItem == data.not_found()) {
return result;
}
+ result.reserve(treeItem->second.size());
for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) {
result.push_back((this->*parseFunc)(innerTreeItem.second));
}
@@ -353,6 +356,7 @@ public:
if (treeItem == data.not_found()) {
return result;
}
+ result.reserve(treeItem->second.size());
for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) {
std::vector<std::shared_ptr<T>> innerResult;
for (const std::pair<const std::string, boost::property_tree::ptree>& innerInnerTreeItem : innerTreeItem.second) {
diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h
index ec4c077..d40619a 100644
--- a/include/tgbot/net/HttpParser.h
+++ b/include/tgbot/net/HttpParser.h
@@ -24,7 +24,7 @@
#define TGBOT_HTTPPARSER_H
#include <string>
-#include <map>
+#include <unordered_map>
#include <vector>
#include "tgbot/net/Url.h"
@@ -43,7 +43,7 @@ public:
std::string generateWwwFormUrlencoded(const std::vector<HttpReqArg>& args);
std::string generateResponse(const std::string& data, const std::string& mimeType = "text/plain", short unsigned statusCode = 200, const std::string& statusStr = "OK", bool isKeepAlive = false);
- inline std::string parseRequest(const std::string& data, std::map<std::string, std::string>& headers) {
+ inline std::string parseRequest(const std::string& data, std::unordered_map<std::string, std::string>& headers) {
return parseHttp(true, data, headers);
}
@@ -51,7 +51,7 @@ public:
return parseHttp(true, data);
}
- inline std::string parseResponse(const std::string& data, std::map<std::string, std::string>& headers) {
+ inline std::string parseResponse(const std::string& data, std::unordered_map<std::string, std::string>& headers) {
return parseHttp(false, data, headers);
}
@@ -60,7 +60,7 @@ public:
}
private:
- std::string parseHttp(bool isRequest, const std::string& data, std::map<std::string, std::string>& headers);
+ std::string parseHttp(bool isRequest, const std::string& data, std::unordered_map<std::string, std::string>& headers);
std::string parseHttp(bool isRequest, const std::string& data);
};
diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h
index e760e29..34cd9c7 100644
--- a/include/tgbot/net/HttpServer.h
+++ b/include/tgbot/net/HttpServer.h
@@ -43,7 +43,7 @@ protected:
class Connection;
public:
- typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler;
+ typedef std::function<std::string (const std::string&, const std::unordered_map<std::string, std::string>)> ServerHandler;
HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
}
@@ -80,7 +80,7 @@ protected:
void start() {
data.reserve(10240);
socket->async_receive(data, [this]() {
- std::map<std::string, std::string> headers;
+ std::unordered_map<std::string, std::string> headers;
std::string body = HttpParser::getInstance().parseResponse(data, headers);
socket->async_send(_handler(body, headers));
});
diff --git a/include/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h
index 9352e82..696d126 100644
--- a/include/tgbot/net/TgWebhookServer.h
+++ b/include/tgbot/net/TgWebhookServer.h
@@ -37,7 +37,7 @@ public:
TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const typename HttpServer<Protocol>::ServerHandler& handler) = delete;
TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const std::string& path, const EventHandler* eventHandler) :
- HttpServer<Protocol>(acceptor, [eventHandler, &path](const std::string& data, const std::map<std::string, std::string>& headers) -> std::string {
+ HttpServer<Protocol>(acceptor, [eventHandler, &path](const std::string& data, const std::unordered_map<std::string, std::string>& headers) -> std::string {
if (headers.at("method") == "POST" && headers.at("path") == path) {
eventHandler->handleUpdate(TgTypeParser::getInstance().parseJsonAndGetUpdate(TgTypeParser::getInstance().parseJson(data)));
}
diff --git a/src/Api.cpp b/src/Api.cpp
index 11349e9..e6c7c4b 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -40,656 +40,691 @@ User::Ptr Api::getMe() const {
Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("text", text));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("text", text);
if (disableWebPagePreview) {
- args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview));
+ args.emplace_back("disable_web_page_preview", disableWebPagePreview);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendMessage", args));
}
Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("from_chat_id", fromChatId));
- args.push_back(HttpReqArg("message_id", messageId));
+ args.reserve(4);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("from_chat_id", fromChatId);
+ args.emplace_back("message_id", messageId);
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("forwardMessage", args));
}
Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photoId));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photoId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName));
+ args.reserve(10);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("audio", audio->data, true, audio->mimeType, audio->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (!performer.empty()){
- args.push_back(HttpReqArg("performer", performer));
+ args.emplace_back("performer", performer);
}
if (!title.empty()){
- args.push_back(HttpReqArg("title", title));
+ args.emplace_back("title", title);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("audio", audioId));
+ args.reserve(10);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("audio", audioId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (!performer.empty()){
- args.push_back(HttpReqArg("performer", performer));
+ args.emplace_back("performer", performer);
}
if (!title.empty()){
- args.push_back(HttpReqArg("title", title));
+ args.emplace_back("title", title);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("document", document->data, true, document->mimeType, document->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("document", document));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("document", document);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker", sticker->data, true, sticker->mimeType, sticker->fileName));
+ args.reserve(5);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker", stickerId));
+ args.reserve(5);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker", stickerId);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
StickerSet::Ptr Api::getStickerSet(const string& name) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("name", name));
+ args.reserve(1);
+ args.emplace_back("name", name);
return TgTypeParser::getInstance().parseJsonAndGetStickerSet(sendRequest("getStickerSet", args));
}
File::Ptr Api::uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
+ args.reserve(2);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("uploadStickerFile", args));
}
bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("contains_mask", containsMasks));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.reserve(7);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("contains_mask", containsMasks);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("contains_mask", containsMasks));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.reserve(7);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("contains_mask", containsMasks);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.reserve(6);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("addStickerToSet", args).get<bool>("", false);
}
bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.reserve(6);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("addStickerToSet", args).get<bool>("", false);
}
bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("sticker", sticker));
- args.push_back(HttpReqArg("position", position));
+ args.reserve(2);
+ args.emplace_back("sticker", sticker);
+ args.emplace_back("position", position);
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
bool Api::deleteStickerPositionInSet(const string& sticker) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("sticker", sticker));
+ args.reserve(1);
+ args.emplace_back("sticker", sticker);
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName));
+ args.reserve(11);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video", video->data, true, video->mimeType, video->fileName);
if (supportsStreaming) {
- args.push_back(HttpReqArg("supports_streaming", supportsStreaming));
+ args.emplace_back("supports_streaming", supportsStreaming);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (width) {
- args.push_back(HttpReqArg("width", width));
+ args.emplace_back("width", width);
}
if (height) {
- args.push_back(HttpReqArg("height", height));
+ args.emplace_back("height", height);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video", videoId));
+ args.reserve(11);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video", videoId);
if (supportsStreaming) {
- args.push_back(HttpReqArg("supports_streaming", supportsStreaming));
+ args.emplace_back("supports_streaming", supportsStreaming);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (width) {
- args.push_back(HttpReqArg("width", width));
+ args.emplace_back("width", width);
}
if (height) {
- args.push_back(HttpReqArg("height", height));
+ args.emplace_back("height", height);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video_note", videoNote));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video_note", videoNote);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (length) {
- args.push_back(HttpReqArg("length", length));
+ args.emplace_back("length", length);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video_note", videoNote));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video_note", videoNote);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (length) {
- args.push_back(HttpReqArg("length", length));
+ args.emplace_back("length", length);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
vector<Message::Ptr> Api::sendMediaGroup(int64_t chatId, const vector<InputMedia::Ptr>& media, bool disableNotification, int32_t replyToMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(4);
+ args.emplace_back("chat_id", chatId);
string mediaJson = TgTypeParser::getInstance().parseArray<InputMedia>(&TgTypeParser::parseInputMedia, media);
- args.push_back(HttpReqArg("media", mediaJson));
- args.push_back(HttpReqArg("disable_notification", disableNotification));
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("media", mediaJson);
+ args.emplace_back("disable_notification", disableNotification);
+ args.emplace_back("reply_to_message_id", replyToMessageId);
return TgTypeParser::getInstance().parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args));
}
Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName));
+ args.reserve(8);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("voice", voice->data, true, voice->mimeType, voice->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration){
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("voice", voiceId));
+ args.reserve(8);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("voice", voiceId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration){
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
Message::Ptr Api::sendGame(int64_t chatId, const std::string& gameShortName, int32_t replyToMessageId, const InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("game_short_name", gameShortName));
+ args.reserve(5);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("game_short_name", gameShortName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendGame", args));
}
Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, uint32_t livePeriod, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
if (livePeriod) {
- args.push_back(HttpReqArg("live_period", livePeriod));
+ args.emplace_back("live_period", livePeriod);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args));
}
Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
+ args.reserve(6);
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (inlineMessageId) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup));
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
Message::Ptr Api::stopMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
+ args.reserve(4);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (inlineMessageId) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup));
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
bool Api::setChatStickerSet(int64_t chatId, const string& stickerSetName) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker_set_name ", stickerSetName));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker_set_name ", stickerSetName);
return sendRequest("setChatStickerSet", args).get<bool>("", false);
}
bool Api::deleteChatStickerSet(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("deleteChatStickerSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("address", address));
+ args.reserve(9);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
+ args.emplace_back("title", title);
+ args.emplace_back("address", address);
if (!foursquareId.empty()) {
- args.push_back(HttpReqArg("foursquare_id", foursquareId));
+ args.emplace_back("foursquare_id", foursquareId);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVenue", args));
}
Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("phone_number", phoneNumber));
- args.push_back(HttpReqArg("first_name", firstName));
- args.push_back(HttpReqArg("last_name", lastName));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("phone_number", phoneNumber);
+ args.emplace_back("first_name", firstName);
+ args.emplace_back("last_name", lastName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendContact", args));
}
void Api::sendChatAction(int64_t chatId, const string& action) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("action", action));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("action", action);
sendRequest("sendChatAction", args);
}
UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, int32_t limit) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(3);
+ args.emplace_back("user_id", userId);
if (offset) {
- args.push_back(HttpReqArg("offset", offset));
+ args.emplace_back("offset", offset);
}
limit = max(1, min(100, limit));
- args.push_back(HttpReqArg("limit", limit));
+ args.emplace_back("limit", limit);
return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args));
}
-File::Ptr Api::getFile(const string &fileId) const
-{
+File::Ptr Api::getFile(const string &fileId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("file_id", fileId));
+ args.reserve(1);
+ args.emplace_back("file_id", fileId);
return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("getFile", args));
}
-bool Api::leaveChat(int64_t chatId) const
-{
+bool Api::leaveChat(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("leaveChat", args).get<bool>("", false);
}
-Chat::Ptr Api::getChat(int64_t chatId) const
-{
+Chat::Ptr Api::getChat(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args));
}
-vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const
-{
+vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return TgTypeParser::getInstance().parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args));
}
-int32_t Api::getChatMembersCount(int64_t chatId) const
-{
+int32_t Api::getChatMembersCount(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("getChatMembersCount", args).get<int32_t>("", 0);
}
-bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, int32_t cacheTime) const
-{
+bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, int32_t cacheTime) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("callback_query_id", callbackQueryId));
+ args.reserve(5);
+ args.emplace_back("callback_query_id", callbackQueryId);
if (!text.empty()) {
- args.push_back(HttpReqArg("text", text));
+ args.emplace_back("text", text);
}
if (showAlert) {
- args.push_back(HttpReqArg("show_alert", showAlert));
+ args.emplace_back("show_alert", showAlert);
}
if (!url.empty()) {
- args.push_back(HttpReqArg("url", url));
+ args.emplace_back("url", url);
}
if (cacheTime) {
- args.push_back(HttpReqArg("cache_time", cacheTime));
+ args.emplace_back("cache_time", cacheTime);
}
return sendRequest("answerCallbackQuery", args).get<bool>("", false);
}
@@ -698,24 +733,25 @@ Message::Ptr Api::editMessageText(const string& text, int64_t chatId, int32_t me
const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("text", text));
+ args.reserve(7);
+ args.emplace_back("text", text);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableWebPagePreview) {
- args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview));
+ args.emplace_back("disable_web_page_preview", disableWebPagePreview);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageText", args);
if (p.get_child_optional("message_id")) {
@@ -729,20 +765,21 @@ Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const st
const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
+ args.reserve(5);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageCaption", args);
if (p.get_child_optional("message_id")) {
@@ -757,17 +794,18 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons
const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
+ args.reserve(4);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageReplyMarkup", args);
if (p.get_child_optional("message_id")) {
@@ -780,39 +818,42 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons
ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
return TgTypeParser::getInstance().parseJsonAndGetChatMember(sendRequest("getChatMember", args));
}
vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout, const StringArrayPtr &allowedUpdates) const {
vector<HttpReqArg> args;
+ args.reserve(4);
if (offset) {
- args.push_back(HttpReqArg("offset", offset));
+ args.emplace_back("offset", offset);
}
limit = max(1, min(100, limit));
- args.push_back(HttpReqArg("limit", limit));
+ args.emplace_back("limit", limit);
if (timeout) {
- args.push_back(HttpReqArg("timeout", timeout));
+ args.emplace_back("timeout", timeout);
}
if (allowedUpdates != nullptr) {
string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<string>(
[](const string &s)->string {
return s;
}, *allowedUpdates);
- args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
+ args.emplace_back("allowed_updates", allowedUpdatesJson);
}
return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args));
}
void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_t maxConnection, const StringArrayPtr &allowedUpdates) const {
vector<HttpReqArg> args;
+ args.reserve(4);
if (!url.empty())
- args.push_back(HttpReqArg("url", url));
+ args.emplace_back("url", url);
if (certificate != nullptr)
- args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName));
+ args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName);
if (maxConnection != 40)
- args.push_back(HttpReqArg("max_connections", maxConnection));
+ args.emplace_back("max_connections", maxConnection);
if (allowedUpdates != nullptr)
{
@@ -820,20 +861,18 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_
[](const string &s)->string {
return s;
}, *allowedUpdates);
- args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
+ args.emplace_back("allowed_updates", allowedUpdatesJson);
}
sendRequest("setWebhook", args);
}
-bool Api::deleteWebhook() const
-{
+bool Api::deleteWebhook() const {
ptree p = sendRequest("deleteWebhook");
return p.get<bool>("", false);
}
-WebhookInfo::Ptr Api::getWebhookInfo() const
-{
+WebhookInfo::Ptr Api::getWebhookInfo() const {
ptree p = sendRequest("getWebhookInfo");
if (!p.get_child_optional("url"))
@@ -852,63 +891,67 @@ WebhookInfo::Ptr Api::getWebhookInfo() const
bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("inline_query_id", inlineQueryId));
+ args.reserve(7);
+ args.emplace_back("inline_query_id", inlineQueryId);
string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results);
- args.push_back(HttpReqArg("results", resultsJson));
+ args.emplace_back("results", resultsJson);
if (cacheTime) {
- args.push_back(HttpReqArg("cache_time", cacheTime));
+ args.emplace_back("cache_time", cacheTime);
}
if (isPersonal) {
- args.push_back(HttpReqArg("is_personal", isPersonal));
+ args.emplace_back("is_personal", isPersonal);
}
if (!nextOffset.empty()) {
- args.push_back(HttpReqArg("next_offset", nextOffset));
+ args.emplace_back("next_offset", nextOffset);
}
if (!switchPmText.empty()) {
- args.push_back(HttpReqArg("switch_pm_text", switchPmText));
+ args.emplace_back("switch_pm_text", switchPmText);
}
if (!switchPmParameter.empty()) {
- args.push_back(HttpReqArg("switch_pm_parameter", switchPmParameter));
+ args.emplace_back("switch_pm_parameter", switchPmParameter);
}
return sendRequest("answerInlineQuery", args).get<bool>("", false);
}
bool Api::kickChatMember(int64_t chatId, int32_t userId, uint64_t untilDate) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(3);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (untilDate) {
- args.push_back(HttpReqArg("until_date", untilDate));
+ args.emplace_back("until_date", untilDate);
}
return sendRequest("kickChatMember", args).get<bool>("", false);
}
bool Api::unbanChatMember(int64_t chatId, int32_t userId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
return sendRequest("unbanChatMember", args).get<bool>("", false);
}
bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate, bool canSendMessages,
bool canSendMediaMessages, bool canSendOtherMessages, bool canAddWebPagePreviews) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(7);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (untilDate) {
- args.push_back(HttpReqArg("until_date", untilDate));
+ args.emplace_back("until_date", untilDate);
}
if (canSendMessages) {
- args.push_back(HttpReqArg("can_send_messages", canSendMessages));
+ args.emplace_back("can_send_messages", canSendMessages);
}
if (canSendMediaMessages) {
- args.push_back(HttpReqArg("can_send_media_messages", canSendMediaMessages));
+ args.emplace_back("can_send_media_messages", canSendMediaMessages);
}
if (canSendOtherMessages) {
- args.push_back(HttpReqArg("can_send_other_messages", canSendOtherMessages));
+ args.emplace_back("can_send_other_messages", canSendOtherMessages);
}
if (canAddWebPagePreviews) {
- args.push_back(HttpReqArg("can_add_web_page_previews", canAddWebPagePreviews));
+ args.emplace_back("can_add_web_page_previews", canAddWebPagePreviews);
}
return sendRequest("restrictChatMember", args).get<bool>("", false);
}
@@ -916,121 +959,131 @@ bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate,
bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, bool canPostMessages,
bool canEditMessages, bool canDeleteMessages, bool canInviteUsers, bool canPinMessages, bool canPromoteMembers) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.reserve(9);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (canChangeInfo) {
- args.push_back(HttpReqArg("can_change_info", canChangeInfo));
+ args.emplace_back("can_change_info", canChangeInfo);
}
if (canPostMessages) {
- args.push_back(HttpReqArg("can_post_messages", canPostMessages));
+ args.emplace_back("can_post_messages", canPostMessages);
}
if (canEditMessages) {
- args.push_back(HttpReqArg("can_edit_messages", canEditMessages));
+ args.emplace_back("can_edit_messages", canEditMessages);
}
if (canDeleteMessages) {
- args.push_back(HttpReqArg("can_delete_messages", canDeleteMessages));
+ args.emplace_back("can_delete_messages", canDeleteMessages);
}
if (canInviteUsers) {
- args.push_back(HttpReqArg("can_invite_users", canInviteUsers));
+ args.emplace_back("can_invite_users", canInviteUsers);
}
if (canPinMessages) {
- args.push_back(HttpReqArg("can_pin_messages", canPinMessages));
+ args.emplace_back("can_pin_messages", canPinMessages);
}
if (canPromoteMembers) {
- args.push_back(HttpReqArg("can_promote_members", canPromoteMembers));
+ args.emplace_back("can_promote_members", canPromoteMembers);
}
return sendRequest("promoteChatMember", args).get<bool>("", false);
}
string Api::exportChatInviteLink(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("exportChatInviteLink", args).get("", "");
}
bool Api::setChatPhoto(int64_t chatId, const InputFile::Ptr photo) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName);
return sendRequest("setChatPhoto", args).get<bool>("", false);
}
bool Api::deleteChatPhoto(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("deleteChatPhoto", args).get<bool>("", false);
}
bool Api::setChatTitle(int64_t chatId, const string& title) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("title", title));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("title", title);
return sendRequest("setChatTitle", args).get<bool>("", false);
}
bool Api::setChatDescription(int64_t chatId, const string& description) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("description", description));
+ args.reserve(2);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("description", description);
return sendRequest("setChatDescription", args).get<bool>("", false);
}
bool Api::pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("message_id", messageId));
+ args.reserve(3);
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("message_id", messageId);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return sendRequest("pinChatMessage", args).get<bool>("", false);
}
bool Api::unpinChatMessage(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.reserve(1);
+ args.emplace_back("chat_id", chatId);
return sendRequest("unpinChatMessage", args).get<bool>("", false);
}
Message::Ptr Api::setGameScore(int32_t userId, int32_t score, bool force, bool disableEditMessage, int64_t chatId, int32_t messageId, const std::string& inlineMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("score", score));
+ args.reserve(7);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("score", score);
if (force) {
- args.push_back(HttpReqArg("force", force));
+ args.emplace_back("force", force);
}
if (disableEditMessage) {
- args.push_back(HttpReqArg("disable_edit_message", disableEditMessage));
+ args.emplace_back("disable_edit_message", disableEditMessage);
}
if (chatId){
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId){
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()){
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("setGameScore", args));
}
vector<GameHighScore::Ptr> Api::getGameHighScores(int32_t userId, int32_t score, bool force, bool disableEditMessage, int64_t chatId, int32_t messageId, const std::string& inlineMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("score", score));
+ args.reserve(7);
+ args.emplace_back("user_id", userId);
+ args.emplace_back("score", score);
if (force) {
- args.push_back(HttpReqArg("force", force));
+ args.emplace_back("force", force);
}
if (disableEditMessage) {
- args.push_back(HttpReqArg("disable_edit_message", disableEditMessage));
+ args.emplace_back("disable_edit_message", disableEditMessage);
}
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()){
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args));
}
diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp
index befbc3b..3dd9215 100644
--- a/src/net/HttpParser.cpp
+++ b/src/net/HttpParser.cpp
@@ -149,7 +149,7 @@ string HttpParser::generateResponse(const string& data, const string& mimeType,
return result;
}
-string HttpParser::parseHttp(bool isRequest, const string& data, map<string, string>& headers) {
+string HttpParser::parseHttp(bool isRequest, const string& data, unordered_map<string, string>& headers) {
bool onlyNewLineChar = false;
size_t headerEnd = data.find("\r\n\r\n");
if (headerEnd == data.npos) {
diff --git a/test/tgbot/net/HttpParser.cpp b/test/tgbot/net/HttpParser.cpp
index 9272736..d0a3703 100644
--- a/test/tgbot/net/HttpParser.cpp
+++ b/test/tgbot/net/HttpParser.cpp
@@ -91,10 +91,10 @@ BOOST_AUTO_TEST_CASE(parseRequest) {
"\r\n"
"testdata";
- map<string, string> tHeaders;
+ unordered_map<string, string> tHeaders;
string t = HttpParser::getInstance().parseRequest(data, tHeaders);
- map<string, string> eHeaders = {
+ unordered_map<string, string> eHeaders = {
{ "method", "POST" },
{ "path", "/index.html" },
{ "host", "example.com" },
@@ -118,10 +118,10 @@ BOOST_AUTO_TEST_CASE(parseResponse) {
"\r\n"
"testdata";
- map<string, string> tHeaders;
+ unordered_map<string, string> tHeaders;
string t = HttpParser::getInstance().parseResponse(data, tHeaders);
- map<string, string> eHeaders = {
+ unordered_map<string, string> eHeaders = {
{ "status", "200" },
{ "content-type", "text/plain" },
{ "content-length", "8" }