summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h')
-rw-r--r--chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h76
1 files changed, 31 insertions, 45 deletions
diff --git a/chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h b/chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h
index 9d0df48b2a9..e72d470fb5b 100644
--- a/chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h
+++ b/chromium/third_party/blink/renderer/core/inspector/v8_inspector_string.h
@@ -11,14 +11,14 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
-#include "third_party/blink/renderer/platform/wtf/decimal.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
-#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
-#include "third_party/blink/renderer/platform/wtf/text/string_to_number.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
+#include "third_party/inspector_protocol/crdtp/cbor.h"
+#include "third_party/inspector_protocol/crdtp/serializable.h"
+#include "third_party/inspector_protocol/crdtp/serializer_traits.h"
#include "v8/include/v8-inspector.h"
namespace blink {
@@ -33,53 +33,12 @@ CORE_EXPORT String ToCoreString(const v8_inspector::StringView&);
CORE_EXPORT String ToCoreString(std::unique_ptr<v8_inspector::StringBuffer>);
namespace protocol {
-
-class Value;
-
using String = WTF::String;
-using StringBuilder = WTF::StringBuilder;
-using ProtocolMessage = WebVector<uint8_t>;
class CORE_EXPORT StringUtil {
STATIC_ONLY(StringUtil);
public:
- static String substring(const String& s, size_t pos, size_t len) {
- return s.Substring(static_cast<wtf_size_t>(pos),
- static_cast<wtf_size_t>(len));
- }
- static String fromInteger(int64_t number) { return String::Number(number); }
- static String fromDouble(double number) {
- return Decimal::FromDouble(number).ToString();
- }
- static double toDouble(const char* s, size_t len, bool* ok) {
- return WTF::CharactersToDouble(reinterpret_cast<const LChar*>(s), len, ok);
- }
- static size_t find(const String& s, const char* needle) {
- return s.Find(needle);
- }
- static size_t find(const String& s, const String& needle) {
- return s.Find(needle);
- }
- static const size_t kNotFound = WTF::kNotFound;
- static void builderAppend(StringBuilder& builder, const String& s) {
- builder.Append(s);
- }
- static void builderAppend(StringBuilder& builder, UChar c) {
- builder.Append(c);
- }
- static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
- builder.Append(s, static_cast<wtf_size_t>(len));
- }
- static void builderAppendQuotedString(StringBuilder&, const String&);
- static void builderReserve(StringBuilder& builder, uint64_t capacity) {
- builder.ReserveCapacity(static_cast<wtf_size_t>(capacity));
- }
- static String builderToString(StringBuilder& builder) {
- return builder.ToString();
- }
- static std::unique_ptr<protocol::Value> parseJSON(const String&);
-
static String fromUTF8(const uint8_t* data, size_t length) {
return String::FromUTF8(reinterpret_cast<const char*>(data), length);
}
@@ -101,7 +60,7 @@ class CORE_EXPORT StringUtil {
};
// A read-only sequence of uninterpreted bytes with reference-counted storage.
-class CORE_EXPORT Binary {
+class CORE_EXPORT Binary : public crdtp::Serializable {
public:
class Impl : public RefCounted<Impl> {
public:
@@ -113,6 +72,9 @@ class CORE_EXPORT Binary {
Binary() = default;
+ // Implements Serializable.
+ void AppendSerialized(std::vector<uint8_t>* out) const override;
+
const uint8_t* data() const { return impl_ ? impl_->data() : nullptr; }
size_t size() const { return impl_ ? impl_->size() : 0; }
@@ -145,4 +107,28 @@ struct hash<WTF::String> {
};
} // namespace std
+// See third_party/inspector_protocol/crdtp/serializer_traits.h.
+namespace crdtp {
+template <>
+struct SerializerTraits<WTF::String> {
+ static void Serialize(const WTF::String& str, std::vector<uint8_t>* out) {
+ if (str.length() == 0) {
+ cbor::EncodeString8(span<uint8_t>(nullptr, 0), out); // Empty string.
+ return;
+ }
+ if (str.Is8Bit()) {
+ cbor::EncodeFromLatin1(
+ span<uint8_t>(reinterpret_cast<const uint8_t*>(str.Characters8()),
+ str.length()),
+ out);
+ return;
+ }
+ cbor::EncodeFromUTF16(
+ span<uint16_t>(reinterpret_cast<const uint16_t*>(str.Characters16()),
+ str.length()),
+ out);
+ }
+};
+} // namespace crdtp
+
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_V8_INSPECTOR_STRING_H_