Commit d3cf03c6 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (v8) ...

... to ec358ccfd63a2a657c147329c7793d217e278a58.

This adds support for CBOR <-> Value.

v8 changes:
- Add StringUTF8Adapter (from Pavel's change)
- Add Binary::fromSpan (needed for the cbor->BinaryValue conversion).

Change-Id: I09746dc361df0b150b23697a20b287613558c003
Reviewed-on: https://chromium-review.googlesource.com/c/1470955
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: 's avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59583}
parent 0988e0d6
...@@ -27,6 +27,16 @@ struct ProtocolMessage { ...@@ -27,6 +27,16 @@ struct ProtocolMessage {
std::vector<uint8_t> binary; std::vector<uint8_t> binary;
}; };
class StringUTF8Adapter {
public:
explicit StringUTF8Adapter(const String& string) : string_(string.utf8()) {}
const char* Data() const { return string_.data(); }
size_t length() const { return string_.length(); }
private:
std::string string_;
};
class StringUtil { class StringUtil {
public: public:
static String substring(const String& s, size_t pos, size_t len) { static String substring(const String& s, size_t pos, size_t len) {
...@@ -91,6 +101,7 @@ class Binary { ...@@ -91,6 +101,7 @@ class Binary {
static Binary fromBase64(const String& base64, bool* success) { static Binary fromBase64(const String& base64, bool* success) {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
static Binary fromSpan(const uint8_t* data, size_t size) { UNIMPLEMENTED(); }
}; };
} // namespace protocol } // namespace protocol
......
...@@ -26,3 +26,8 @@ to fetch the package (and dependencies) and build and run the tests: ...@@ -26,3 +26,8 @@ to fetch the package (and dependencies) and build and run the tests:
gn gen out/Release gn gen out/Release
ninja -C out/Release json_parser_test ninja -C out/Release json_parser_test
out/Release/json_parser_test out/Release/json_parser_test
You'll probably also need to install g++, since Clang uses this to find the
standard C++ headers. E.g.,
sudo apt-get install g++-8
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: a0abcb6bfbd8d13071bb0d2ac4ee1066703eb60a Revision: ec358ccfd63a2a657c147329c7793d217e278a58
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
# #
# Adding --show_changes to the command line prints out a list of valid public API changes. # Adding --show_changes to the command line prints out a list of valid public API changes.
from __future__ import print_function
import copy import copy
import os.path import os.path
import optparse import optparse
...@@ -475,9 +476,9 @@ def main(): ...@@ -475,9 +476,9 @@ def main():
if arg_options.show_changes: if arg_options.show_changes:
changes = compare_schemas(domains, baseline_domains, True) changes = compare_schemas(domains, baseline_domains, True)
if len(changes) > 0: if len(changes) > 0:
print " Public changes since %s:" % version print(" Public changes since %s:" % version)
for change in changes: for change in changes:
print " %s" % change print(" %s" % change)
if arg_options.stamp: if arg_options.stamp:
with open(arg_options.stamp, 'a') as _: with open(arg_options.stamp, 'a') as _:
......
...@@ -36,6 +36,7 @@ public: ...@@ -36,6 +36,7 @@ public:
TypeInteger, TypeInteger,
TypeDouble, TypeDouble,
TypeString, TypeString,
TypeBinary,
TypeObject, TypeObject,
TypeArray, TypeArray,
TypeSerialized TypeSerialized
...@@ -49,14 +50,15 @@ public: ...@@ -49,14 +50,15 @@ public:
virtual bool asDouble(double* output) const; virtual bool asDouble(double* output) const;
virtual bool asInteger(int* output) const; virtual bool asInteger(int* output) const;
virtual bool asString(String* output) const; virtual bool asString(String* output) const;
virtual bool asBinary(Binary* output) const;
virtual void writeJSON(StringBuilder* output) const; virtual void writeJSON(StringBuilder* output) const;
virtual void writeBinary(std::vector<uint8_t>* bytes) const;
virtual std::unique_ptr<Value> clone() const; virtual std::unique_ptr<Value> clone() const;
String toJSONString() const; String toJSONString() const;
String serializeToJSON() override; String serializeToJSON() override;
std::vector<uint8_t> serializeToBinary() override; std::vector<uint8_t> serializeToBinary() override;
protected: protected:
Value() : m_type(TypeNull) { } Value() : m_type(TypeNull) { }
explicit Value(ValueType type) : m_type(type) { } explicit Value(ValueType type) : m_type(type) { }
...@@ -89,6 +91,7 @@ public: ...@@ -89,6 +91,7 @@ public:
bool asDouble(double* output) const override; bool asDouble(double* output) const override;
bool asInteger(int* output) const override; bool asInteger(int* output) const override;
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -117,6 +120,7 @@ public: ...@@ -117,6 +120,7 @@ public:
bool asString(String* output) const override; bool asString(String* output) const override;
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -126,6 +130,24 @@ private: ...@@ -126,6 +130,24 @@ private:
String m_stringValue; String m_stringValue;
}; };
class {{config.lib.export_macro}} BinaryValue : public Value {
public:
static std::unique_ptr<BinaryValue> create(const Binary& value)
{
return std::unique_ptr<BinaryValue>(new BinaryValue(value));
}
bool asBinary(Binary* output) const override;
void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
private:
explicit BinaryValue(const Binary& value) : Value(TypeBinary), m_binaryValue(value) { }
Binary m_binaryValue;
};
class {{config.lib.export_macro}} SerializedValue : public Value { class {{config.lib.export_macro}} SerializedValue : public Value {
public: public:
static std::unique_ptr<SerializedValue> fromJSON(const String& value) static std::unique_ptr<SerializedValue> fromJSON(const String& value)
...@@ -139,6 +161,7 @@ public: ...@@ -139,6 +161,7 @@ public:
} }
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -171,6 +194,7 @@ public: ...@@ -171,6 +194,7 @@ public:
} }
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
size_t size() const { return m_data.size(); } size_t size() const { return m_data.size(); }
...@@ -239,6 +263,7 @@ public: ...@@ -239,6 +263,7 @@ public:
~ListValue() override; ~ListValue() override;
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
void pushValue(std::unique_ptr<Value>); void pushValue(std::unique_ptr<Value>);
......
...@@ -223,6 +223,12 @@ Binary Binary::fromString(std::string data) { ...@@ -223,6 +223,12 @@ Binary Binary::fromString(std::string data) {
return Binary(base::RefCountedString::TakeString(&data)); return Binary(base::RefCountedString::TakeString(&data));
} }
// static
Binary Binary::fromSpan(const uint8_t* data, size_t size) {
return Binary(scoped_refptr<base::RefCountedBytes>(
new base::RefCountedBytes(data, size)));
}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
...@@ -32,6 +32,16 @@ class Value; ...@@ -32,6 +32,16 @@ class Value;
using String = std::string; using String = std::string;
using ProtocolMessage = std::string; using ProtocolMessage = std::string;
class {{config.lib.export_macro}} StringUTF8Adapter {
public:
StringUTF8Adapter(const std::string& string) : string_(string) { }
const char* Data() const { return string_.data(); }
size_t length() const { return string_.length(); }
private:
const std::string& string_;
};
class {{config.lib.export_macro}} StringBuilder { class {{config.lib.export_macro}} StringBuilder {
public: public:
StringBuilder(); StringBuilder();
...@@ -87,13 +97,14 @@ class {{config.lib.export_macro}} StringUtil { ...@@ -87,13 +97,14 @@ class {{config.lib.export_macro}} StringUtil {
static String builderToString(StringBuilder& builder) { static String builderToString(StringBuilder& builder) {
return builder.toString(); return builder.toString();
} }
static std::vector<uint8_t> utf8data(const String& str) {
return std::vector<uint8_t>(str.begin(), str.end());
}
static std::unique_ptr<Value> parseMessage(const std::string& message, bool binary); static std::unique_ptr<Value> parseMessage(const std::string& message, bool binary);
static ProtocolMessage jsonToMessage(String message); static ProtocolMessage jsonToMessage(String message);
static ProtocolMessage binaryToMessage(std::vector<uint8_t> message); static ProtocolMessage binaryToMessage(std::vector<uint8_t> message);
static String fromUTF8(const uint8_t* data, size_t length) {
return std::string(reinterpret_cast<const char*>(data), length);
}
}; };
// A read-only sequence of uninterpreted bytes with reference-counted storage. // A read-only sequence of uninterpreted bytes with reference-counted storage.
...@@ -113,6 +124,7 @@ class {{config.lib.export_macro}} Binary { ...@@ -113,6 +124,7 @@ class {{config.lib.export_macro}} Binary {
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory); static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t> data); static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data); static Binary fromString(std::string data);
static Binary fromSpan(const uint8_t* data, size_t size);
private: private:
explicit Binary(scoped_refptr<base::RefCountedMemory> bytes); explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment