Commit 6f6942db authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (v8)

New revision: d2fc9b958e1eeb1e956f3e2208afa9923bdc9b67

To roll this I need to update some call sites; this is because the
Serializable interface is changing.

Upstream change / review was here:
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1879870

Change-Id: I93c4747609c6003baf1c160a68b8fb6bb07ac565
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1879519Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64618}
parent 6b70b090
...@@ -163,7 +163,7 @@ protocol::DictionaryValue* V8InspectorSessionImpl::agentState( ...@@ -163,7 +163,7 @@ protocol::DictionaryValue* V8InspectorSessionImpl::agentState(
std::unique_ptr<StringBuffer> V8InspectorSessionImpl::serializeForFrontend( std::unique_ptr<StringBuffer> V8InspectorSessionImpl::serializeForFrontend(
std::unique_ptr<protocol::Serializable> message) { std::unique_ptr<protocol::Serializable> message) {
std::vector<uint8_t> cbor = message->serializeToBinary(); std::vector<uint8_t> cbor = std::move(*message).TakeSerialized();
if (use_binary_protocol_) if (use_binary_protocol_)
return std::unique_ptr<StringBuffer>( return std::unique_ptr<StringBuffer>(
new BinaryStringBuffer(std::move(cbor))); new BinaryStringBuffer(std::move(cbor)));
...@@ -366,9 +366,7 @@ void V8InspectorSessionImpl::dispatchProtocolMessage( ...@@ -366,9 +366,7 @@ void V8InspectorSessionImpl::dispatchProtocolMessage(
} }
std::vector<uint8_t> V8InspectorSessionImpl::state() { std::vector<uint8_t> V8InspectorSessionImpl::state() {
std::vector<uint8_t> out; return std::move(*m_state).TakeSerialized();
m_state->writeBinary(&out);
return out;
} }
std::vector<std::unique_ptr<protocol::Schema::API::Domain>> std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
......
...@@ -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: bbc72612409377752c8fd2e7a63a1a5947b7dc4b Revision: d2fc9b958e1eeb1e956f3e2208afa9923bdc9b67
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -142,9 +142,9 @@ public: ...@@ -142,9 +142,9 @@ public:
return std::unique_ptr<ProtocolError>(new ProtocolError(code, errorMessage)); return std::unique_ptr<ProtocolError>(new ProtocolError(code, errorMessage));
} }
std::vector<uint8_t> serializeToBinary() override void AppendSerialized(std::vector<uint8_t>* out) const override
{ {
return serialize()->serializeToBinary(); toDictionary()->AppendSerialized(out);
} }
~ProtocolError() override {} ~ProtocolError() override {}
...@@ -156,7 +156,7 @@ private: ...@@ -156,7 +156,7 @@ private:
{ {
} }
std::unique_ptr<DictionaryValue> serialize() { std::unique_ptr<DictionaryValue> toDictionary() const {
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create(); std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
error->setInteger("code", m_code); error->setInteger("code", m_code);
error->setString("message", m_errorMessage); error->setString("message", m_errorMessage);
...@@ -299,13 +299,13 @@ UberDispatcher::~UberDispatcher() = default; ...@@ -299,13 +299,13 @@ UberDispatcher::~UberDispatcher() = default;
// static // static
std::unique_ptr<Serializable> InternalResponse::createResponse(int callId, std::unique_ptr<Serializable> params) std::unique_ptr<Serializable> InternalResponse::createResponse(int callId, std::unique_ptr<Serializable> params)
{ {
return std::unique_ptr<Serializable>(new InternalResponse(callId, String(), std::move(params))); return std::unique_ptr<Serializable>(new InternalResponse(callId, nullptr, std::move(params)));
} }
// static // static
std::unique_ptr<Serializable> InternalResponse::createNotification(const String& notification, std::unique_ptr<Serializable> params) std::unique_ptr<Serializable> InternalResponse::createNotification(const char* method, std::unique_ptr<Serializable> params)
{ {
return std::unique_ptr<Serializable>(new InternalResponse(0, notification, std::move(params))); return std::unique_ptr<Serializable>(new InternalResponse(0, method, std::move(params)));
} }
// static // static
...@@ -314,23 +314,39 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId, ...@@ -314,23 +314,39 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId,
return ProtocolError::createErrorResponse(callId, code, message, nullptr); return ProtocolError::createErrorResponse(callId, code, message, nullptr);
} }
std::vector<uint8_t> InternalResponse::serializeToBinary() void InternalResponse::AppendSerialized(std::vector<uint8_t>* out) const
{ {
std::unique_ptr<DictionaryValue> result = DictionaryValue::create(); using {{config.encoding_lib.namespace}}::cbor::NewCBOREncoder;
std::unique_ptr<Serializable> params(m_params ? std::move(m_params) : DictionaryValue::create()); using {{config.encoding_lib.namespace}}::StreamingParserHandler;
if (m_notification.length()) { using {{config.encoding_lib.namespace}}::Status;
result->setString("method", m_notification); using {{config.encoding_lib.namespace}}::SpanFrom;
result->setValue("params", SerializedValue::fromBinary(params->serializeToBinary()));
Status status;
std::unique_ptr<StreamingParserHandler> encoder =
NewCBOREncoder(out, &status);
encoder->HandleMapBegin();
if (m_method) {
encoder->HandleString8(SpanFrom("method"));
encoder->HandleString8(SpanFrom(m_method));
encoder->HandleString8(SpanFrom("params"));
} else { } else {
result->setInteger("id", m_callId); encoder->HandleString8(SpanFrom("id"));
result->setValue("result", SerializedValue::fromBinary(params->serializeToBinary())); encoder->HandleInt32(m_callId);
encoder->HandleString8(SpanFrom("result"));
} }
return result->serializeToBinary(); if (m_params) {
m_params->AppendSerialized(out);
} else {
encoder->HandleMapBegin();
encoder->HandleMapEnd();
}
encoder->HandleMapEnd();
DCHECK(status.ok());
} }
InternalResponse::InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params) InternalResponse::InternalResponse(int callId, const char* method, std::unique_ptr<Serializable> params)
: m_callId(callId) : m_callId(callId)
, m_notification(notification) , m_method(method)
, m_params(params ? std::move(params) : nullptr) , m_params(params ? std::move(params) : nullptr)
{ {
} }
......
...@@ -129,18 +129,18 @@ class InternalResponse : public Serializable { ...@@ -129,18 +129,18 @@ class InternalResponse : public Serializable {
PROTOCOL_DISALLOW_COPY(InternalResponse); PROTOCOL_DISALLOW_COPY(InternalResponse);
public: public:
static std::unique_ptr<Serializable> createResponse(int callId, std::unique_ptr<Serializable> params); static std::unique_ptr<Serializable> createResponse(int callId, std::unique_ptr<Serializable> params);
static std::unique_ptr<Serializable> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr); static std::unique_ptr<Serializable> createNotification(const char* method, std::unique_ptr<Serializable> params = nullptr);
static std::unique_ptr<Serializable> createErrorResponse(int callId, DispatchResponse::ErrorCode code, const String& message); static std::unique_ptr<Serializable> createErrorResponse(int callId, DispatchResponse::ErrorCode code, const String& message);
std::vector<uint8_t> serializeToBinary() override; void AppendSerialized(std::vector<uint8_t>* out) const override;
~InternalResponse() override {} ~InternalResponse() override {}
private: private:
InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params); InternalResponse(int callId, const char* method, std::unique_ptr<Serializable> params);
int m_callId; int m_callId;
String m_notification; const char* m_method = nullptr;
std::unique_ptr<Serializable> m_params; std::unique_ptr<Serializable> m_params;
}; };
...@@ -153,11 +153,15 @@ public: ...@@ -153,11 +153,15 @@ public:
~InternalRawNotification() override {} ~InternalRawNotification() override {}
std::vector<uint8_t> serializeToBinary() override std::vector<uint8_t> TakeSerialized() && override {
{
return std::move(m_binaryNotification); return std::move(m_binaryNotification);
} }
void AppendSerialized(std::vector<uint8_t>* out) const override
{
out->insert(out->end(), m_binaryNotification.begin(), m_binaryNotification.end());
}
private: private:
explicit InternalRawNotification(std::vector<uint8_t> notification) explicit InternalRawNotification(std::vector<uint8_t> notification)
: m_binaryNotification(std::move(notification)) { } : m_binaryNotification(std::move(notification)) { }
......
...@@ -13,7 +13,12 @@ namespace {{namespace}} { ...@@ -13,7 +13,12 @@ namespace {{namespace}} {
class {{config.lib.export_macro}} Serializable { class {{config.lib.export_macro}} Serializable {
public: public:
virtual std::vector<uint8_t> serializeToBinary() = 0; virtual std::vector<uint8_t> TakeSerialized() && {
std::vector<uint8_t> out;
AppendSerialized(&out);
return out;
}
virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
virtual ~Serializable() = default; virtual ~Serializable() = default;
}; };
......
...@@ -281,7 +281,7 @@ void Value::writeJSON(StringBuilder* output) const ...@@ -281,7 +281,7 @@ void Value::writeJSON(StringBuilder* output) const
StringUtil::builderAppend(*output, nullValueString, 4); StringUtil::builderAppend(*output, nullValueString, 4);
} }
void Value::writeBinary(std::vector<uint8_t>* bytes) const { void Value::AppendSerialized(std::vector<uint8_t>* bytes) const {
DCHECK(m_type == TypeNull); DCHECK(m_type == TypeNull);
bytes->push_back(cbor::EncodeNull()); bytes->push_back(cbor::EncodeNull());
} }
...@@ -299,12 +299,6 @@ String Value::toJSONString() const ...@@ -299,12 +299,6 @@ String Value::toJSONString() const
return StringUtil::builderToString(result); return StringUtil::builderToString(result);
} }
std::vector<uint8_t> Value::serializeToBinary() {
std::vector<uint8_t> bytes;
writeBinary(&bytes);
return bytes;
}
bool FundamentalValue::asBoolean(bool* output) const bool FundamentalValue::asBoolean(bool* output) const
{ {
if (type() != TypeBoolean) if (type() != TypeBoolean)
...@@ -353,7 +347,7 @@ void FundamentalValue::writeJSON(StringBuilder* output) const ...@@ -353,7 +347,7 @@ void FundamentalValue::writeJSON(StringBuilder* output) const
} }
} }
void FundamentalValue::writeBinary(std::vector<uint8_t>* bytes) const { void FundamentalValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
switch (type()) { switch (type()) {
case TypeDouble: case TypeDouble:
cbor::EncodeDouble(m_doubleValue, bytes); cbor::EncodeDouble(m_doubleValue, bytes);
...@@ -422,7 +416,7 @@ void EncodeString(const String& s, std::vector<uint8_t>* out) { ...@@ -422,7 +416,7 @@ void EncodeString(const String& s, std::vector<uint8_t>* out) {
} }
} // namespace } // namespace
void StringValue::writeBinary(std::vector<uint8_t>* bytes) const { void StringValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
EncodeString(m_stringValue, bytes); EncodeString(m_stringValue, bytes);
} }
...@@ -443,7 +437,7 @@ void BinaryValue::writeJSON(StringBuilder* output) const ...@@ -443,7 +437,7 @@ void BinaryValue::writeJSON(StringBuilder* output) const
StringUtil::builderAppendQuotedString(*output, m_binaryValue.toBase64()); StringUtil::builderAppendQuotedString(*output, m_binaryValue.toBase64());
} }
void BinaryValue::writeBinary(std::vector<uint8_t>* bytes) const { void BinaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(), cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(),
m_binaryValue.size()), bytes); m_binaryValue.size()), bytes);
} }
...@@ -459,7 +453,11 @@ void SerializedValue::writeJSON(StringBuilder* output) const ...@@ -459,7 +453,11 @@ void SerializedValue::writeJSON(StringBuilder* output) const
StringUtil::builderAppend(*output, m_serializedJSON); StringUtil::builderAppend(*output, m_serializedJSON);
} }
void SerializedValue::writeBinary(std::vector<uint8_t>* output) const std::vector<uint8_t> SerializedValue::TakeSerialized() && {
return std::move(m_serializedBinary);
}
void SerializedValue::AppendSerialized(std::vector<uint8_t>* output) const
{ {
DCHECK(type() == TypeSerialized); DCHECK(type() == TypeSerialized);
output->insert(output->end(), m_serializedBinary.begin(), m_serializedBinary.end()); output->insert(output->end(), m_serializedBinary.begin(), m_serializedBinary.end());
...@@ -607,7 +605,7 @@ void DictionaryValue::writeJSON(StringBuilder* output) const ...@@ -607,7 +605,7 @@ void DictionaryValue::writeJSON(StringBuilder* output) const
StringUtil::builderAppend(*output, '}'); StringUtil::builderAppend(*output, '}');
} }
void DictionaryValue::writeBinary(std::vector<uint8_t>* bytes) const { void DictionaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EnvelopeEncoder encoder; cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes); encoder.EncodeStart(bytes);
bytes->push_back(cbor::EncodeIndefiniteLengthMapStart()); bytes->push_back(cbor::EncodeIndefiniteLengthMapStart());
...@@ -616,7 +614,7 @@ void DictionaryValue::writeBinary(std::vector<uint8_t>* bytes) const { ...@@ -616,7 +614,7 @@ void DictionaryValue::writeBinary(std::vector<uint8_t>* bytes) const {
Dictionary::const_iterator value = m_data.find(key); Dictionary::const_iterator value = m_data.find(key);
DCHECK(value != m_data.cend() && value->second); DCHECK(value != m_data.cend() && value->second);
EncodeString(key, bytes); EncodeString(key, bytes);
value->second->writeBinary(bytes); value->second->AppendSerialized(bytes);
} }
bytes->push_back(cbor::EncodeStop()); bytes->push_back(cbor::EncodeStop());
encoder.EncodeStop(bytes); encoder.EncodeStop(bytes);
...@@ -656,12 +654,12 @@ void ListValue::writeJSON(StringBuilder* output) const ...@@ -656,12 +654,12 @@ void ListValue::writeJSON(StringBuilder* output) const
StringUtil::builderAppend(*output, ']'); StringUtil::builderAppend(*output, ']');
} }
void ListValue::writeBinary(std::vector<uint8_t>* bytes) const { void ListValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EnvelopeEncoder encoder; cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes); encoder.EncodeStart(bytes);
bytes->push_back(cbor::EncodeIndefiniteLengthArrayStart()); bytes->push_back(cbor::EncodeIndefiniteLengthArrayStart());
for (size_t i = 0; i < m_data.size(); ++i) { for (size_t i = 0; i < m_data.size(); ++i) {
m_data[i]->writeBinary(bytes); m_data[i]->AppendSerialized(bytes);
} }
bytes->push_back(cbor::EncodeStop()); bytes->push_back(cbor::EncodeStop());
encoder.EncodeStop(bytes); encoder.EncodeStop(bytes);
......
...@@ -54,10 +54,9 @@ public: ...@@ -54,10 +54,9 @@ public:
virtual bool asBinary(Binary* 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 void AppendSerialized(std::vector<uint8_t>* bytes) const override;
virtual std::unique_ptr<Value> clone() const; virtual std::unique_ptr<Value> clone() const;
String toJSONString() const; String toJSONString() const;
std::vector<uint8_t> serializeToBinary() override;
protected: protected:
Value() : m_type(TypeNull) { } Value() : m_type(TypeNull) { }
...@@ -91,7 +90,7 @@ public: ...@@ -91,7 +90,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; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -120,7 +119,7 @@ public: ...@@ -120,7 +119,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; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -139,7 +138,7 @@ public: ...@@ -139,7 +138,7 @@ public:
bool asBinary(Binary* output) const override; bool asBinary(Binary* output) const override;
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -161,7 +160,8 @@ public: ...@@ -161,7 +160,8 @@ public:
} }
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override; std::vector<uint8_t> TakeSerialized() && override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
private: private:
...@@ -194,7 +194,7 @@ public: ...@@ -194,7 +194,7 @@ public:
} }
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
void writeBinary(std::vector<uint8_t>* bytes) const override; void AppendSerialized(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(); }
...@@ -263,7 +263,7 @@ public: ...@@ -263,7 +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; void AppendSerialized(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>);
......
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
String local_json = ({{config.imported.from_imported_string % "std::move(json)"}}); String local_json = ({{config.imported.from_imported_string % "std::move(json)"}});
StringUtil::builderAppend(*output, local_json); StringUtil::builderAppend(*output, local_json);
} }
void writeBinary(std::vector<uint8_t>* output) const override { void AppendSerialized(std::vector<uint8_t>* output) const override {
m_exported->writeBinary(output); m_exported->writeBinary(output);
} }
std::unique_ptr<Value> clone() const override { std::unique_ptr<Value> clone() const override {
...@@ -61,7 +61,7 @@ struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai ...@@ -61,7 +61,7 @@ struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai
} }
std::vector<uint8_t> binary; std::vector<uint8_t> binary;
value->writeBinary(&binary); value->AppendSerialized(&binary);
auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}::fromBinary(binary.data(), binary.size()); auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}::fromBinary(binary.data(), binary.size());
if (!result) if (!result)
errors->addError("cannot parse"); errors->addError("cannot parse");
......
...@@ -107,7 +107,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const ...@@ -107,7 +107,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
void {{type.id}}::writeBinary(std::vector<uint8_t>* out) const void {{type.id}}::writeBinary(std::vector<uint8_t>* out) const
{ {
toValue()->writeBinary(out); toValue()->AppendSerialized(out);
} }
// static // static
......
...@@ -100,7 +100,9 @@ public: ...@@ -100,7 +100,9 @@ public:
{% endfor %} {% endfor %}
std::unique_ptr<protocol::DictionaryValue> toValue() const; std::unique_ptr<protocol::DictionaryValue> toValue() const;
std::vector<uint8_t> serializeToBinary() override { return toValue()->serializeToBinary(); } void AppendSerialized(std::vector<uint8_t>* out) const override {
toValue()->AppendSerialized(out);
}
String toJSON() const { return toValue()->toJSONString(); } String toJSON() const { return toValue()->toJSONString(); }
std::unique_ptr<{{type.id}}> clone() const; std::unique_ptr<{{type.id}}> clone() const;
{% if protocol.is_exported(domain.domain, type.id) %} {% if protocol.is_exported(domain.domain, type.id) %}
......
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