Skip to content

Commit 5ceb2d0

Browse files
committed
Merge branch 'issue_4_use_zero_copy'
2 parents deca6ee + df4961d commit 5ceb2d0

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -360,22 +360,12 @@ bool UniversalTelegramBot::setMyCommands(const String& commandArray) {
360360
return false;
361361
}
362362

363-
DynamicJsonDocument _commandArray(maxMessageLength);
364-
DeserializationError err = deserializeJson(_commandArray, commandArray);
365-
if (err) {
366-
#if defined(_debug)
367-
Serial.println(F("sendSetMyCommands: Deserialization Error"));
368-
Serial.println(commandArray);
369-
#endif // defined(_debug)
370-
return false;
371-
}
372-
373363
DynamicJsonDocument payload(maxMessageLength);
374364
payload["commands"] = serialized(commandArray);
375365
bool sent = false;
376366
String response = "";
377367
#if defined(_debug)
378-
Serial.println(F("sendSetMyCommands: SEND Post /setMyCommands"));
368+
Serial.println(F("sendSetMyCommands: SEND Post /setMyCommands"));
379369
#endif // defined(_debug)
380370
unsigned long sttime = millis();
381371

@@ -621,14 +611,7 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard(
621611

622612
JsonObject replyMarkup = payload.createNestedObject("reply_markup");
623613

624-
// Reply keyboard is an array of arrays.
625-
// Outer array represents rows
626-
// Inner arrays represents columns
627-
// This example "ledon" and "ledoff" are two buttons on the top row
628-
// and "status is a single button on the next row"
629-
DynamicJsonDocument keyboardBuffer(maxMessageLength); // creating a buffer enough to keep keyboard string
630-
deserializeJson(keyboardBuffer, keyboard);
631-
replyMarkup["keyboard"] = keyboardBuffer.as<JsonArray>();
614+
replyMarkup["keyboard"] = serialized(keyboard);
632615

633616
// Telegram defaults these values to false, so to decrease the size of the
634617
// payload we will only send them if needed
@@ -657,9 +640,7 @@ bool UniversalTelegramBot::sendMessageWithInlineKeyboard(String chat_id,
657640
payload["parse_mode"] = parse_mode;
658641

659642
JsonObject replyMarkup = payload.createNestedObject("reply_markup");
660-
DynamicJsonDocument keyboardBuffer(maxMessageLength); // assuming keyboard buffer will alwas be limited to 1024 bytes
661-
deserializeJson(keyboardBuffer, keyboard);
662-
replyMarkup["inline_keyboard"] = keyboardBuffer.as<JsonArray>();
643+
replyMarkup["inline_keyboard"] = serialized(keyboard);
663644
return sendPostMessage(payload.as<JsonObject>());
664645
}
665646

@@ -760,15 +741,13 @@ String UniversalTelegramBot::sendPhoto(String chat_id, String photo,
760741

761742
if (!keyboard.isEmpty()) {
762743
JsonObject replyMarkup = payload.createNestedObject("reply_markup");
763-
DynamicJsonDocument keyboardBuffer(maxMessageLength); // assuming keyboard buffer will alwas be limited to 1024 bytes
764-
deserializeJson(keyboardBuffer, keyboard);
765-
replyMarkup["keyboard"] = keyboardBuffer.as<JsonArray>();
744+
replyMarkup["keyboard"] = serialized(keyboard);
766745
}
767746

768747
return sendPostPhoto(payload.as<JsonObject>());
769748
}
770749

771-
bool UniversalTelegramBot::checkForOkResponse(String response) {
750+
bool UniversalTelegramBot::checkForOkResponse(String &response) {
772751
int last_id;
773752
DynamicJsonDocument doc(response.length());
774753
deserializeJson(doc, response);

src/UniversalTelegramBot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class UniversalTelegramBot {
104104
bool setMyCommands(const String& commandArray);
105105

106106
int getUpdates(long offset);
107-
bool checkForOkResponse(String response);
107+
bool checkForOkResponse(String &response);
108108
telegramMessage messages[HANDLE_MESSAGES];
109109
long last_message_received;
110110
String name;

0 commit comments

Comments
 (0)