Do not overload send as this causes issues with folly::dynamic

Summary:
folly::dynamic, std::string, implicit constructors and method overloading is not a good combination.

This renames the send method to sendRaw as to avoid issues with existing plugins currently sending string params.

Reviewed By: mweststrate

Differential Revision: D38827539

fbshipit-source-id: 653f62e41ebfbe93d1af25f39c81f6b05bf84cb4
This commit is contained in:
Lorenzo Blasa
2022-08-18 09:39:42 -07:00
committed by Facebook GitHub Bot
parent 92d1f7b77a
commit d1c06c9c46
8 changed files with 12 additions and 10 deletions

View File

@@ -524,7 +524,7 @@ class JFlipperConnectionImpl
}
void sendString(const std::string method, const std::string params) {
_connection->send(std::move(method), std::move(params));
_connection->sendRaw(std::move(method), std::move(params));
}
void sendObject(

View File

@@ -38,7 +38,9 @@ class FlipperConnection {
identifier.
Note: The `message` argument is expected to contain a valid JSON.
*/
virtual void send(const std::string& method, const std::string& params) = 0;
virtual void sendRaw(
const std::string& method,
const std::string& params) = 0;
/**
Report an error to the Flipper desktop app

View File

@@ -53,7 +53,7 @@ class FlipperConnectionImpl : public FlipperConnection {
socket_->sendMessage(message);
}
void send(const std::string& method, const std::string& params) override {
void sendRaw(const std::string& method, const std::string& params) override {
std::stringstream ss;
ss << "{"
"\"method\": \"execute\","
@@ -66,8 +66,8 @@ class FlipperConnectionImpl : public FlipperConnection {
<< "\","
"\"params\":"
<< params << "}}";
socket_->sendMessage(ss.str());
auto message = ss.str();
socket_->sendMessage(message);
}
void error(const std::string& message, const std::string& stacktrace)

View File

@@ -58,7 +58,7 @@ class FlipperConnectionManager {
Send message to the ws server.
Note: The `message` argument is expected to contain a valid JSON.
*/
virtual void sendMessage(const std::string& message) = 0;
virtual void sendMessageRaw(const std::string& message) = 0;
/**
Handler for connection and message receipt from the ws server.

View File

@@ -341,7 +341,7 @@ void FlipperConnectionManagerImpl::sendMessage(const folly::dynamic& message) {
});
}
void FlipperConnectionManagerImpl::sendMessage(const std::string& message) {
void FlipperConnectionManagerImpl::sendMessageRaw(const std::string& message) {
flipperScheduler_->schedule([this, message]() {
try {
if (client_) {

View File

@@ -42,7 +42,7 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager {
void sendMessage(const folly::dynamic& message) override;
void sendMessage(const std::string& message) override;
void sendMessageRaw(const std::string& message) override;
void onMessageReceived(
const folly::dynamic& message,

View File

@@ -40,7 +40,7 @@ class FlipperConnectionManagerMock : public FlipperConnectionManager {
messages.push_back(message);
}
void sendMessage(const std::string& message) override {
void sendMessageRaw(const std::string& message) override {
messages.push_back(folly::parseJson(message));
}

View File

@@ -23,7 +23,7 @@ class FlipperConnectionMock : public FlipperConnection {
sent_message_history[method].push(params);
}
void send(const std::string& method, const std::string& params) override {
void sendRaw(const std::string& method, const std::string& params) override {
sent_[method] = folly::parseJson(params);
sent_message_history[method].push(params);
}