1 |
|
|
// Bridges V8 Inspector generated code with the std::string used by the Node |
2 |
|
|
// Compare to V8 counterpart - deps/v8/src/inspector/string-util.h |
3 |
|
|
#ifndef SRC_INSPECTOR_NODE_STRING_H_ |
4 |
|
|
#define SRC_INSPECTOR_NODE_STRING_H_ |
5 |
|
|
|
6 |
|
|
#include "util.h" |
7 |
|
|
#include "v8-inspector.h" |
8 |
|
|
|
9 |
|
|
#include <cstring> |
10 |
|
|
#include <sstream> |
11 |
|
|
#include <string> |
12 |
|
|
|
13 |
|
|
namespace node { |
14 |
|
|
namespace inspector { |
15 |
|
|
namespace protocol { |
16 |
|
|
|
17 |
|
|
class Value; |
18 |
|
|
|
19 |
|
|
using String = std::string; |
20 |
|
|
using StringBuilder = std::ostringstream; |
21 |
|
|
using ProtocolMessage = std::string; |
22 |
|
|
|
23 |
|
|
namespace StringUtil { |
24 |
|
|
// NOLINTNEXTLINE(runtime/references) This is V8 API... |
25 |
|
1186141 |
inline void builderAppend(StringBuilder& builder, char c) { |
26 |
|
1186141 |
builder.put(c); |
27 |
|
1186141 |
} |
28 |
|
|
|
29 |
|
|
// NOLINTNEXTLINE(runtime/references) |
30 |
|
38139 |
inline void builderAppend(StringBuilder& builder, const char* value, |
31 |
|
|
size_t length) { |
32 |
|
38139 |
builder.write(value, length); |
33 |
|
38139 |
} |
34 |
|
|
|
35 |
|
|
// NOLINTNEXTLINE(runtime/references) |
36 |
|
38126 |
inline void builderAppend(StringBuilder& builder, const char* value) { |
37 |
|
38126 |
builderAppend(builder, value, std::strlen(value)); |
38 |
|
38126 |
} |
39 |
|
|
|
40 |
|
|
// NOLINTNEXTLINE(runtime/references) |
41 |
|
697 |
inline void builderAppend(StringBuilder& builder, const String& string) { |
42 |
|
697 |
builder << string; |
43 |
|
697 |
} |
44 |
|
|
|
45 |
|
|
// NOLINTNEXTLINE(runtime/references) |
46 |
|
85591 |
inline void builderReserve(StringBuilder& builder, size_t) { |
47 |
|
|
// ostringstream does not have a counterpart |
48 |
|
85591 |
} |
49 |
|
39 |
inline String substring(const String& string, size_t start, size_t count) { |
50 |
|
39 |
return string.substr(start, count); |
51 |
|
|
} |
52 |
|
43 |
inline String fromInteger(int n) { |
53 |
|
43 |
return std::to_string(n); |
54 |
|
|
} |
55 |
|
85591 |
inline String builderToString(const StringBuilder& builder) { |
56 |
|
85591 |
return builder.str(); |
57 |
|
|
} |
58 |
|
39 |
inline size_t find(const String& string, const char* substring) { |
59 |
|
39 |
return string.find(substring); |
60 |
|
|
} |
61 |
|
|
String fromDouble(double d); |
62 |
|
|
double toDouble(const char* buffer, size_t length, bool* ok); |
63 |
|
|
|
64 |
|
|
String StringViewToUtf8(v8_inspector::StringView view); |
65 |
|
|
|
66 |
|
|
// NOLINTNEXTLINE(runtime/references) |
67 |
|
|
void builderAppendQuotedString(StringBuilder& builder, const String&); |
68 |
|
|
std::unique_ptr<Value> parseJSON(const String&); |
69 |
|
|
std::unique_ptr<Value> parseJSON(v8_inspector::StringView view); |
70 |
|
|
|
71 |
|
|
std::unique_ptr<Value> parseMessage(const std::string& message, bool binary); |
72 |
|
|
ProtocolMessage jsonToMessage(String message); |
73 |
|
|
ProtocolMessage binaryToMessage(std::vector<uint8_t> message); |
74 |
|
|
String fromUTF8(const uint8_t* data, size_t length); |
75 |
|
|
String fromUTF16(const uint16_t* data, size_t length); |
76 |
|
|
const uint8_t* CharactersUTF8(const String& s); |
77 |
|
|
size_t CharacterCount(const String& s); |
78 |
|
|
|
79 |
|
|
// Unimplemented. The generated code will fall back to CharactersUTF8(). |
80 |
|
|
inline uint8_t* CharactersLatin1(const String& s) { return nullptr; } |
81 |
|
|
inline const uint16_t* CharactersUTF16(const String& s) { return nullptr; } |
82 |
|
|
|
83 |
|
|
extern size_t kNotFound; |
84 |
|
|
} // namespace StringUtil |
85 |
|
|
|
86 |
|
|
// A read-only sequence of uninterpreted bytes with reference-counted storage. |
87 |
|
|
// Though the templates for generating the protocol bindings reference |
88 |
|
|
// this type, js_protocol.pdl doesn't have a field of type 'binary', so |
89 |
|
|
// therefore it's unnecessary to provide an implementation here. |
90 |
|
|
class Binary { |
91 |
|
|
public: |
92 |
|
|
const uint8_t* data() const { UNREACHABLE(); } |
93 |
|
|
size_t size() const { UNREACHABLE(); } |
94 |
|
|
String toBase64() const { UNREACHABLE(); } |
95 |
|
|
static Binary fromBase64(const String& base64, bool* success) { |
96 |
|
|
UNREACHABLE(); |
97 |
|
|
} |
98 |
|
|
static Binary fromSpan(const uint8_t* data, size_t size) { UNREACHABLE(); } |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
} // namespace protocol |
102 |
|
|
} // namespace inspector |
103 |
|
|
} // namespace node |
104 |
|
|
|
105 |
|
|
#endif // SRC_INSPECTOR_NODE_STRING_H_ |