|
35 | 35 |
|
36 | 36 | #include "UniversalTelegramBot.h"
|
37 | 37 |
|
| 38 | +#define ZERO_COPY(STR) ((char*)STR.c_str()) |
| 39 | + |
38 | 40 | UniversalTelegramBot::UniversalTelegramBot(String token, Client &client) {
|
39 | 41 | _token = token;
|
40 | 42 | #ifdef ARDUINO_ESP8266_RELEASE_2_5_0
|
@@ -330,7 +332,7 @@ bool UniversalTelegramBot::getMe() {
|
330 | 332 | String command = "bot" + _token + "/getMe";
|
331 | 333 | String response = sendGetToTelegram(command); // receive reply from telegram.org
|
332 | 334 | DynamicJsonDocument doc(maxMessageLength);
|
333 |
| - DeserializationError error = deserializeJson(doc, response); |
| 335 | + DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); |
334 | 336 | closeClient();
|
335 | 337 |
|
336 | 338 | if (!error) {
|
@@ -424,7 +426,7 @@ int UniversalTelegramBot::getUpdates(long offset) {
|
424 | 426 |
|
425 | 427 | // Parse response into Json object
|
426 | 428 | DynamicJsonDocument doc(maxMessageLength);
|
427 |
| - DeserializationError error = deserializeJson(doc, response); |
| 429 | + DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); |
428 | 430 | #ifdef _debug
|
429 | 431 | Serial.print(F("GetUpdates parsed jsonDoc: "));
|
430 | 432 | serializeJson(doc, Serial);
|
@@ -820,7 +822,7 @@ bool UniversalTelegramBot::getFile(String *file_path, long *file_size, String fi
|
820 | 822 | String command = "bot" + _token + "/getFile?file_id=" + file_id;
|
821 | 823 | String response = sendGetToTelegram(command); // receive reply from telegram.org
|
822 | 824 | DynamicJsonDocument doc(maxMessageLength);
|
823 |
| - DeserializationError error = deserializeJson(doc, response); |
| 825 | + DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); |
824 | 826 | JsonObject obj = doc.as<JsonObject>(); //there is nothing better right now to use obj.containsKey("result")
|
825 | 827 | closeClient();
|
826 | 828 |
|
|
0 commit comments