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 {
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 {
public:
static String substring(const String& s, size_t pos, size_t len) {
......@@ -91,6 +101,7 @@ class Binary {
static Binary fromBase64(const String& base64, bool* success) {
UNIMPLEMENTED();
}
static Binary fromSpan(const uint8_t* data, size_t size) { UNIMPLEMENTED(); }
};
} // namespace protocol
......
......@@ -26,3 +26,8 @@ to fetch the package (and dependencies) and build and run the tests:
gn gen out/Release
ninja -C 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
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: a0abcb6bfbd8d13071bb0d2ac4ee1066703eb60a
Revision: ec358ccfd63a2a657c147329c7793d217e278a58
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -45,6 +45,7 @@
#
# Adding --show_changes to the command line prints out a list of valid public API changes.
from __future__ import print_function
import copy
import os.path
import optparse
......@@ -475,9 +476,9 @@ def main():
if arg_options.show_changes:
changes = compare_schemas(domains, baseline_domains, True)
if len(changes) > 0:
print " Public changes since %s:" % version
print(" Public changes since %s:" % version)
for change in changes:
print " %s" % change
print(" %s" % change)
if arg_options.stamp:
with open(arg_options.stamp, 'a') as _:
......
......@@ -36,6 +36,7 @@ public:
TypeInteger,
TypeDouble,
TypeString,
TypeBinary,
TypeObject,
TypeArray,
TypeSerialized
......@@ -49,14 +50,15 @@ public:
virtual bool asDouble(double* output) const;
virtual bool asInteger(int* output) const;
virtual bool asString(String* output) const;
virtual bool asBinary(Binary* output) const;
virtual void writeJSON(StringBuilder* output) const;
virtual void writeBinary(std::vector<uint8_t>* bytes) const;
virtual std::unique_ptr<Value> clone() const;
String toJSONString() const;
String serializeToJSON() override;
std::vector<uint8_t> serializeToBinary() override;
protected:
Value() : m_type(TypeNull) { }
explicit Value(ValueType type) : m_type(type) { }
......@@ -89,6 +91,7 @@ public:
bool asDouble(double* output) const override;
bool asInteger(int* 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:
......@@ -117,6 +120,7 @@ public:
bool asString(String* 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:
......@@ -126,6 +130,24 @@ private:
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 {
public:
static std::unique_ptr<SerializedValue> fromJSON(const String& value)
......@@ -139,6 +161,7 @@ public:
}
void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
private:
......@@ -171,6 +194,7 @@ public:
}
void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
size_t size() const { return m_data.size(); }
......@@ -239,6 +263,7 @@ public:
~ListValue() override;
void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
void pushValue(std::unique_ptr<Value>);
......
......@@ -223,6 +223,12 @@ Binary Binary::fromString(std::string 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 %}
} // namespace {{namespace}}
{% endfor %}
......@@ -32,6 +32,16 @@ class Value;
using String = 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 {
public:
StringBuilder();
......@@ -87,13 +97,14 @@ class {{config.lib.export_macro}} StringUtil {
static String builderToString(StringBuilder& builder) {
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 ProtocolMessage jsonToMessage(String 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.
......@@ -113,6 +124,7 @@ class {{config.lib.export_macro}} Binary {
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data);
static Binary fromSpan(const uint8_t* data, size_t size);
private:
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