Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: templates/Imported_h.template

Issue 2526603002: [inspector_protocol] Introduce protocol::Serializable (Closed)
Patch Set: minor fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Values_h.template ('k') | templates/TypeBuilder_cpp.template » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file is generated 1 // This file is generated
2 2
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be 4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file. 5 // found in the LICENSE file.
6 6
7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h 7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h
8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h 8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h
9 9
10 #include {{format_include(config.protocol.package, "Protocol")}} 10 #include {{format_include(config.protocol.package, "Protocol")}}
11 {% if config.imported.header %} 11 {% if config.imported.header %}
12 #include {{format_include(config.imported.header)}} 12 #include {{format_include(config.imported.header)}}
13 {% else %} 13 {% else %}
14 #include {{format_include(config.imported.package, domain.domain)}} 14 #include {{format_include(config.imported.package, domain.domain)}}
15 {% endif %} 15 {% endif %}
16 16
17 {% for namespace in config.protocol.namespace %} 17 {% for namespace in config.protocol.namespace %}
18 namespace {{namespace}} { 18 namespace {{namespace}} {
19 {% endfor %} 19 {% endfor %}
20 {% for type in domain.types %} 20 {% for type in domain.types %}
21 {% if not (type.type == "object") or not ("properties" in type) or not (type .exported) %}{% continue %}{% endif %} 21 {% if not (type.type == "object") or not ("properties" in type) or not (type .exported) %}{% continue %}{% endif %}
22 22
23 template<> 23 template<>
24 struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai n}}::API::{{type.id}}> { 24 struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai n}}::API::{{type.id}}> {
25 static std::unique_ptr<{{"::".join(config.imported.namespace)}}::{{domain.do main}}::API::{{type.id}}> parse(protocol::Value* value, ErrorSupport* errors) 25 static std::unique_ptr<{{"::".join(config.imported.namespace)}}::{{domain.do main}}::API::{{type.id}}> fromValue(protocol::Value* value, ErrorSupport* errors )
26 { 26 {
27 if (!value) { 27 if (!value) {
28 errors->addError("value expected"); 28 errors->addError("value expected");
29 return nullptr; 29 return nullptr;
30 } 30 }
31 String json = value->toJSONString(); 31 String json = value->serialize();
32 auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain} }::API::{{type.id}}::fromJSONString({{config.imported.to_imported_string % "json "}}); 32 auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain} }::API::{{type.id}}::fromJSONString({{config.imported.to_imported_string % "json "}});
33 if (!result) 33 if (!result)
34 errors->addError("cannot parse"); 34 errors->addError("cannot parse");
35 return result; 35 return result;
36 } 36 }
37 37
38 static std::unique_ptr<protocol::Value> serialize(const {{"::".join(config.i mported.namespace)}}::{{domain.domain}}::API::{{type.id}}* value) 38 static std::unique_ptr<protocol::Value> toValue(const {{"::".join(config.imp orted.namespace)}}::{{domain.domain}}::API::{{type.id}}* value)
39 { 39 {
40 auto json = value->toJSONString(); 40 auto json = value->toJSONString();
41 return SerializedValue::create({{config.imported.from_imported_string % "std::move(json)"}}); 41 return SerializedValue::create({{config.imported.from_imported_string % "std::move(json)"}});
42 } 42 }
43 43
44 static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<{{": :".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}>& valu e) 44 static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<{{"::" .join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}>& value)
45 { 45 {
46 return serialize(value.get()); 46 return toValue(value.get());
47 } 47 }
48 }; 48 };
49 {% endfor %} 49 {% endfor %}
50 50
51 {% for namespace in config.protocol.namespace %} 51 {% for namespace in config.protocol.namespace %}
52 } // namespace {{namespace}} 52 } // namespace {{namespace}}
53 {% endfor %} 53 {% endfor %}
54 54
55 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imp orted_h) 55 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imp orted_h)
OLDNEW
« no previous file with comments | « lib/Values_h.template ('k') | templates/TypeBuilder_cpp.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698