11cb0ef41Sopenharmony_ci// Bridges V8 Inspector generated code with the std::string used by the Node 21cb0ef41Sopenharmony_ci// Compare to V8 counterpart - deps/v8/src/inspector/string-util.h 31cb0ef41Sopenharmony_ci#ifndef SRC_INSPECTOR_NODE_STRING_H_ 41cb0ef41Sopenharmony_ci#define SRC_INSPECTOR_NODE_STRING_H_ 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci#include "util.h" 71cb0ef41Sopenharmony_ci#include "v8-inspector.h" 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci#include <cstring> 101cb0ef41Sopenharmony_ci#include <sstream> 111cb0ef41Sopenharmony_ci#include <string> 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinamespace node { 141cb0ef41Sopenharmony_cinamespace inspector { 151cb0ef41Sopenharmony_cinamespace protocol { 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciclass Value; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciusing String = std::string; 201cb0ef41Sopenharmony_ciusing StringBuilder = std::ostringstream; 211cb0ef41Sopenharmony_ciusing ProtocolMessage = std::string; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_cinamespace StringUtil { 241cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) This is V8 API... 251cb0ef41Sopenharmony_ciinline void builderAppend(StringBuilder& builder, char c) { 261cb0ef41Sopenharmony_ci builder.put(c); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) 301cb0ef41Sopenharmony_ciinline void builderAppend(StringBuilder& builder, const char* value, 311cb0ef41Sopenharmony_ci size_t length) { 321cb0ef41Sopenharmony_ci builder.write(value, length); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) 361cb0ef41Sopenharmony_ciinline void builderAppend(StringBuilder& builder, const char* value) { 371cb0ef41Sopenharmony_ci builderAppend(builder, value, std::strlen(value)); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) 411cb0ef41Sopenharmony_ciinline void builderAppend(StringBuilder& builder, const String& string) { 421cb0ef41Sopenharmony_ci builder << string; 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) 461cb0ef41Sopenharmony_ciinline void builderReserve(StringBuilder& builder, size_t) { 471cb0ef41Sopenharmony_ci // ostringstream does not have a counterpart 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_ciinline String substring(const String& string, size_t start, size_t count) { 501cb0ef41Sopenharmony_ci return string.substr(start, count); 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ciinline String fromInteger(int n) { 531cb0ef41Sopenharmony_ci return std::to_string(n); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ciinline String builderToString(const StringBuilder& builder) { 561cb0ef41Sopenharmony_ci return builder.str(); 571cb0ef41Sopenharmony_ci} 581cb0ef41Sopenharmony_ciinline size_t find(const String& string, const char* substring) { 591cb0ef41Sopenharmony_ci return string.find(substring); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ciString fromDouble(double d); 621cb0ef41Sopenharmony_cidouble toDouble(const char* buffer, size_t length, bool* ok); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ciString StringViewToUtf8(v8_inspector::StringView view); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci// NOLINTNEXTLINE(runtime/references) 671cb0ef41Sopenharmony_civoid builderAppendQuotedString(StringBuilder& builder, const std::string_view); 681cb0ef41Sopenharmony_cistd::unique_ptr<Value> parseJSON(const std::string_view); 691cb0ef41Sopenharmony_cistd::unique_ptr<Value> parseJSON(v8_inspector::StringView view); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_cistd::unique_ptr<Value> parseMessage(const std::string_view message, 721cb0ef41Sopenharmony_ci bool binary); 731cb0ef41Sopenharmony_ciProtocolMessage jsonToMessage(String message); 741cb0ef41Sopenharmony_ciProtocolMessage binaryToMessage(std::vector<uint8_t> message); 751cb0ef41Sopenharmony_ciString fromUTF8(const uint8_t* data, size_t length); 761cb0ef41Sopenharmony_ciString fromUTF16(const uint16_t* data, size_t length); 771cb0ef41Sopenharmony_ciconst uint8_t* CharactersUTF8(const std::string_view s); 781cb0ef41Sopenharmony_cisize_t CharacterCount(const std::string_view s); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci// Unimplemented. The generated code will fall back to CharactersUTF8(). 811cb0ef41Sopenharmony_ciinline uint8_t* CharactersLatin1(const std::string_view s) { 821cb0ef41Sopenharmony_ci return nullptr; 831cb0ef41Sopenharmony_ci} 841cb0ef41Sopenharmony_ciinline const uint16_t* CharactersUTF16(const std::string_view s) { 851cb0ef41Sopenharmony_ci return nullptr; 861cb0ef41Sopenharmony_ci} 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ciextern size_t kNotFound; 891cb0ef41Sopenharmony_ci} // namespace StringUtil 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci// A read-only sequence of uninterpreted bytes with reference-counted storage. 921cb0ef41Sopenharmony_ci// Though the templates for generating the protocol bindings reference 931cb0ef41Sopenharmony_ci// this type, js_protocol.pdl doesn't have a field of type 'binary', so 941cb0ef41Sopenharmony_ci// therefore it's unnecessary to provide an implementation here. 951cb0ef41Sopenharmony_ciclass Binary { 961cb0ef41Sopenharmony_ci public: 971cb0ef41Sopenharmony_ci const uint8_t* data() const { UNREACHABLE(); } 981cb0ef41Sopenharmony_ci size_t size() const { UNREACHABLE(); } 991cb0ef41Sopenharmony_ci String toBase64() const { UNREACHABLE(); } 1001cb0ef41Sopenharmony_ci static Binary fromBase64(const std::string_view base64, bool* success) { 1011cb0ef41Sopenharmony_ci UNREACHABLE(); 1021cb0ef41Sopenharmony_ci } 1031cb0ef41Sopenharmony_ci static Binary fromSpan(const uint8_t* data, size_t size) { UNREACHABLE(); } 1041cb0ef41Sopenharmony_ci}; 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci} // namespace protocol 1071cb0ef41Sopenharmony_ci} // namespace inspector 1081cb0ef41Sopenharmony_ci} // namespace node 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci#endif // SRC_INSPECTOR_NODE_STRING_H_ 111