From 5c66ec9e66d2a5e6ba678c67051b1fb8d9fea581 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 29 Sep 2023 21:58:09 -0400 Subject: [PATCH] inspector: simplify dispatchProtocolMessage PR-URL: https://github.com/nodejs/node/pull/49780 Reviewed-By: Yagiz Nizipli --- src/inspector/node_string.cc | 10 ---------- src/inspector/node_string.h | 2 -- src/inspector_agent.cc | 4 ++-- .../lib/base_string_adapter_cc.template | 12 ------------ .../lib/base_string_adapter_h.template | 1 - 5 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/inspector/node_string.cc b/src/inspector/node_string.cc index 0f780f46c8ebdd..7960971a094fd4 100644 --- a/src/inspector/node_string.cc +++ b/src/inspector/node_string.cc @@ -97,16 +97,6 @@ double toDouble(const char* buffer, size_t length, bool* ok) { return d; } -std::unique_ptr parseMessage(const std::string_view message, - bool binary) { - if (binary) { - return Value::parseBinary( - reinterpret_cast(message.data()), - message.length()); - } - return parseJSON(message); -} - ProtocolMessage jsonToMessage(String message) { return message; } diff --git a/src/inspector/node_string.h b/src/inspector/node_string.h index e36da446248ef1..369041841ef96d 100644 --- a/src/inspector/node_string.h +++ b/src/inspector/node_string.h @@ -68,8 +68,6 @@ void builderAppendQuotedString(StringBuilder& builder, const std::string_view); std::unique_ptr parseJSON(const std::string_view); std::unique_ptr parseJSON(v8_inspector::StringView view); -std::unique_ptr parseMessage(const std::string_view message, - bool binary); ProtocolMessage jsonToMessage(String message); ProtocolMessage binaryToMessage(std::vector message); String fromUTF8(const uint8_t* data, size_t length); diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index f0b4cc43c864ae..de372400fd9ced 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -253,8 +253,8 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel, "[inspector received] %s\n", raw_message); std::unique_ptr value = - protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage( - raw_message, false)); + protocol::DictionaryValue::cast( + protocol::StringUtil::parseJSON(message)); int call_id; std::string method; node_dispatcher_->parseCommand(value.get(), &call_id, &method); diff --git a/tools/inspector_protocol/lib/base_string_adapter_cc.template b/tools/inspector_protocol/lib/base_string_adapter_cc.template index 639b39bb520d85..af078b8e8ae729 100644 --- a/tools/inspector_protocol/lib/base_string_adapter_cc.template +++ b/tools/inspector_protocol/lib/base_string_adapter_cc.template @@ -128,18 +128,6 @@ std::unique_ptr toBaseValue(Value* value, int depth) { return nullptr; } -// static -std::unique_ptr StringUtil::parseMessage( - const std::string& message, bool binary) { - if (binary) { - return Value::parseBinary( - reinterpret_cast(message.data()), - message.length()); - } - std::unique_ptr value = base::JSONReader::ReadDeprecated(message); - return toProtocolValue(value.get(), 1000); -} - // static ProtocolMessage StringUtil::jsonToMessage(String message) { return message; diff --git a/tools/inspector_protocol/lib/base_string_adapter_h.template b/tools/inspector_protocol/lib/base_string_adapter_h.template index 8bf3c355c0e584..46f9e1778b12bb 100644 --- a/tools/inspector_protocol/lib/base_string_adapter_h.template +++ b/tools/inspector_protocol/lib/base_string_adapter_h.template @@ -92,7 +92,6 @@ class {{config.lib.export_macro}} StringUtil { return builder.toString(); } - static std::unique_ptr parseMessage(const std::string& message, bool binary); static ProtocolMessage jsonToMessage(String message); static ProtocolMessage binaryToMessage(std::vector message);