Skip to content

Commit deca6ee

Browse files
committed
Merge branch 'issue_4_use_zero_copy'
2 parents 223af83 + 396037d commit deca6ee

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include "UniversalTelegramBot.h"
3737

38+
#define ZERO_COPY(STR) ((char*)STR.c_str())
39+
3840
UniversalTelegramBot::UniversalTelegramBot(String token, Client &client) {
3941
_token = token;
4042
#ifdef ARDUINO_ESP8266_RELEASE_2_5_0
@@ -330,7 +332,7 @@ bool UniversalTelegramBot::getMe() {
330332
String command = "bot" + _token + "/getMe";
331333
String response = sendGetToTelegram(command); // receive reply from telegram.org
332334
DynamicJsonDocument doc(maxMessageLength);
333-
DeserializationError error = deserializeJson(doc, response);
335+
DeserializationError error = deserializeJson(doc, ZERO_COPY(response));
334336
closeClient();
335337

336338
if (!error) {
@@ -424,7 +426,7 @@ int UniversalTelegramBot::getUpdates(long offset) {
424426

425427
// Parse response into Json object
426428
DynamicJsonDocument doc(maxMessageLength);
427-
DeserializationError error = deserializeJson(doc, response);
429+
DeserializationError error = deserializeJson(doc, ZERO_COPY(response));
428430
#ifdef _debug
429431
Serial.print(F("GetUpdates parsed jsonDoc: "));
430432
serializeJson(doc, Serial);
@@ -820,7 +822,7 @@ bool UniversalTelegramBot::getFile(String *file_path, long *file_size, String fi
820822
String command = "bot" + _token + "/getFile?file_id=" + file_id;
821823
String response = sendGetToTelegram(command); // receive reply from telegram.org
822824
DynamicJsonDocument doc(maxMessageLength);
823-
DeserializationError error = deserializeJson(doc, response);
825+
DeserializationError error = deserializeJson(doc, ZERO_COPY(response));
824826
JsonObject obj = doc.as<JsonObject>(); //there is nothing better right now to use obj.containsKey("result")
825827
closeClient();
826828

0 commit comments

Comments
 (0)