Commit 556b6e31 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Roll inspector_protocol to 460186cff1f0eead0d418626e7e75f52105182b2.

See
https://chromium.googlesource.com/deps/inspector_protocol/+/460186cff1f0eead0d418626e7e75f52105182b2

Bug: chromium:891377
Change-Id: I77a350b5338d17c9cd0bf18423abcfe2d6f1e4eb
Reviewed-on: https://chromium-review.googlesource.com/c/1297606
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602381}
parent 76dfdded
...@@ -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: 7c91103242e0bc0bbf4120e459506b5f0736cd26 Revision: 460186cff1f0eead0d418626e7e75f52105182b2
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -168,6 +168,11 @@ def compare_types(context, kind, type_1, type_2, types_map_1, types_map_2, depth ...@@ -168,6 +168,11 @@ def compare_types(context, kind, type_1, type_2, types_map_1, types_map_2, depth
base_type_1 = type_1["type"] base_type_1 = type_1["type"]
base_type_2 = type_2["type"] base_type_2 = type_2["type"]
# Binary and string have the same wire representation in JSON.
if ((base_type_1 == "string" and base_type_2 == "binary") or
(base_type_2 == "string" and base_type_1 == "binary")):
return
if base_type_1 != base_type_2: if base_type_1 != base_type_2:
errors.append("%s: %s base type mismatch, '%s' vs '%s'" % (context, kind, base_type_1, base_type_2)) errors.append("%s: %s base type mismatch, '%s' vs '%s'" % (context, kind, base_type_1, base_type_2))
elif base_type_1 == "object": elif base_type_1 == "object":
......
...@@ -266,6 +266,21 @@ def create_string_type_definition(): ...@@ -266,6 +266,21 @@ def create_string_type_definition():
} }
def create_binary_type_definition():
# pylint: disable=W0622
return {
"return_type": "Binary",
"pass_type": "const Binary&",
"to_pass_type": "%s",
"to_raw_type": "%s",
"to_rvalue": "%s",
"type": "Binary",
"raw_type": "Binary",
"raw_pass_type": "const Binary&",
"raw_return_type": "Binary",
}
def create_primitive_type_definition(type): def create_primitive_type_definition(type):
# pylint: disable=W0622 # pylint: disable=W0622
typedefs = { typedefs = {
...@@ -443,8 +458,10 @@ class Protocol(object): ...@@ -443,8 +458,10 @@ class Protocol(object):
self.type_definitions["boolean"] = create_primitive_type_definition("boolean") self.type_definitions["boolean"] = create_primitive_type_definition("boolean")
self.type_definitions["object"] = create_object_type_definition() self.type_definitions["object"] = create_object_type_definition()
self.type_definitions["any"] = create_any_type_definition() self.type_definitions["any"] = create_any_type_definition()
self.type_definitions["binary"] = create_binary_type_definition()
for domain in self.json_api["domains"]: for domain in self.json_api["domains"]:
self.type_definitions[domain["domain"] + ".string"] = create_string_type_definition() self.type_definitions[domain["domain"] + ".string"] = create_string_type_definition()
self.type_definitions[domain["domain"] + ".binary"] = create_binary_type_definition()
if not ("types" in domain): if not ("types" in domain):
continue continue
for type in domain["types"]: for type in domain["types"]:
...@@ -457,6 +474,8 @@ class Protocol(object): ...@@ -457,6 +474,8 @@ class Protocol(object):
self.type_definitions[type_name] = self.resolve_type(type) self.type_definitions[type_name] = self.resolve_type(type)
elif type["type"] == domain["domain"] + ".string": elif type["type"] == domain["domain"] + ".string":
self.type_definitions[type_name] = create_string_type_definition() self.type_definitions[type_name] = create_string_type_definition()
elif type["type"] == domain["domain"] + ".binary":
self.type_definitions[type_name] = create_binary_type_definition()
else: else:
self.type_definitions[type_name] = create_primitive_type_definition(type["type"]) self.type_definitions[type_name] = create_primitive_type_definition(type["type"])
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import argparse
import collections import collections
import json import json
import os.path import os.path
...@@ -12,19 +13,22 @@ import sys ...@@ -12,19 +13,22 @@ import sys
import pdl import pdl
def main(argv): def main(argv):
if len(argv) < 2: parser = argparse.ArgumentParser(description=(
sys.stderr.write("Usage: %s <protocol.pdl> <protocol.json>\n" % sys.argv[0]) "Converts from .pdl to .json by invoking the pdl Python module."))
return 1 parser.add_argument('--map_binary_to_string', type=bool,
file_name = os.path.normpath(argv[0]) help=('If set, binary in the .pdl is mapped to a '
'string in .json. Client code will have to '
'base64 decode the string to get the payload.'))
parser.add_argument("pdl_file", help="The .pdl input file to parse.")
parser.add_argument("json_file", help="The .json output file write.")
args = parser.parse_args(argv)
file_name = os.path.normpath(args.pdl_file)
input_file = open(file_name, "r") input_file = open(file_name, "r")
pdl_string = input_file.read() pdl_string = input_file.read()
protocol = pdl.loads(pdl_string, file_name) protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string)
input_file.close() input_file.close()
output_file = open(argv[0].replace('.pdl', '.json'), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close()
output_file = open(os.path.normpath(argv[1]), 'wb') output_file = open(os.path.normpath(args.json_file), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': ')) json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close() output_file.close()
......
...@@ -116,6 +116,15 @@ public: ...@@ -116,6 +116,15 @@ public:
using MaybeBase::operator=; using MaybeBase::operator=;
}; };
template<>
class Maybe<Binary> : public MaybeBase<Binary> {
public:
Maybe() { }
Maybe(Binary value) : MaybeBase(value) { }
Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
......
...@@ -99,6 +99,28 @@ struct ValueConversions<String> { ...@@ -99,6 +99,28 @@ struct ValueConversions<String> {
} }
}; };
template<>
struct ValueConversions<Binary> {
static Binary fromValue(protocol::Value* value, ErrorSupport* errors)
{
String result;
bool success = value ? value->asString(&result) : false;
if (!success) {
errors->addError("string value expected");
return Binary();
}
Binary out = Binary::fromBase64(result, &success);
if (!success)
errors->addError("base64 decoding error");
return out;
}
static std::unique_ptr<protocol::Value> toValue(const Binary& value)
{
return StringValue::create(value.toBase64());
}
};
template<> template<>
struct ValueConversions<Value> { struct ValueConversions<Value> {
static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors) static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
......
...@@ -10,18 +10,21 @@ import sys ...@@ -10,18 +10,21 @@ import sys
description = '' description = ''
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array']
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array', 'binary']
def assignType(item, type, isArray=False):
if isArray: def assignType(item, type, is_array=False, map_binary_to_string=False):
if is_array:
item['type'] = 'array' item['type'] = 'array'
item['items'] = collections.OrderedDict() item['items'] = collections.OrderedDict()
assignType(item['items'], type) assignType(item['items'], type, False, map_binary_to_string)
return return
if type == 'enum': if type == 'enum':
type = 'string' type = 'string'
if map_binary_to_string and type == 'binary':
type = 'string'
if type in primitiveTypes: if type in primitiveTypes:
item['type'] = type item['type'] = type
else: else:
...@@ -42,7 +45,7 @@ def createItem(d, experimental, deprecated, name=None): ...@@ -42,7 +45,7 @@ def createItem(d, experimental, deprecated, name=None):
return result return result
def parse(data, file_name): def parse(data, file_name, map_binary_to_string=False):
protocol = collections.OrderedDict() protocol = collections.OrderedDict()
protocol['version'] = collections.OrderedDict() protocol['version'] = collections.OrderedDict()
protocol['domains'] = [] protocol['domains'] = []
...@@ -88,7 +91,7 @@ def parse(data, file_name): ...@@ -88,7 +91,7 @@ def parse(data, file_name):
if 'types' not in domain: if 'types' not in domain:
domain['types'] = [] domain['types'] = []
item = createItem({'id': match.group(3)}, match.group(1), match.group(2)) item = createItem({'id': match.group(3)}, match.group(1), match.group(2))
assignType(item, match.group(5), match.group(4)) assignType(item, match.group(5), match.group(4), map_binary_to_string)
domain['types'].append(item) domain['types'].append(item)
continue continue
...@@ -115,7 +118,7 @@ def parse(data, file_name): ...@@ -115,7 +118,7 @@ def parse(data, file_name):
param = createItem({}, match.group(1), match.group(2), match.group(6)) param = createItem({}, match.group(1), match.group(2), match.group(6))
if match.group(3): if match.group(3):
param['optional'] = True param['optional'] = True
assignType(param, match.group(5), match.group(4)) assignType(param, match.group(5), match.group(4), map_binary_to_string)
if match.group(5) == 'enum': if match.group(5) == 'enum':
enumliterals = param['enum'] = [] enumliterals = param['enum'] = []
subitems.append(param) subitems.append(param)
...@@ -161,7 +164,7 @@ def parse(data, file_name): ...@@ -161,7 +164,7 @@ def parse(data, file_name):
return protocol return protocol
def loads(data, file_name): def loads(data, file_name, map_binary_to_string=False):
if file_name.endswith(".pdl"): if file_name.endswith(".pdl"):
return parse(data, file_name) return parse(data, file_name, map_binary_to_string)
return json.loads(data) return json.loads(data)
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