| OLD | NEW |
| (Empty) |
| 1 // This file is generated | |
| 2 | |
| 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 | |
| 5 // found in the LICENSE file. | |
| 6 | |
| 7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h | |
| 8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h | |
| 9 | |
| 10 #include "{{config.protocol.package}}/Protocol.h" | |
| 11 #include "{{config.imported.package}}/{{domain.domain}}.h" | |
| 12 | |
| 13 {% for namespace in config.protocol.namespace %} | |
| 14 namespace {{namespace}} { | |
| 15 {% endfor %} | |
| 16 {% for type in domain.types %} | |
| 17 {% if not (type.type == "object") or not ("properties" in type) or not (type
.exported) %}{% continue %}{% endif %} | |
| 18 | |
| 19 template<> | |
| 20 struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai
n}}::API::{{type.id}}> { | |
| 21 static std::unique_ptr<{{"::".join(config.imported.namespace)}}::{{domain.do
main}}::API::{{type.id}}> parse(protocol::Value* value, ErrorSupport* errors) | |
| 22 { | |
| 23 if (!value) { | |
| 24 errors->addError("value expected"); | |
| 25 return nullptr; | |
| 26 } | |
| 27 String json = value->toJSONString(); | |
| 28 auto result = {{"::".join(config.imported.namespace)}}::{{domain.domain}
}::API::{{type.id}}::fromJSONString({{config.imported.to_imported_string % "json
"}}); | |
| 29 if (!result) | |
| 30 errors->addError("cannot parse"); | |
| 31 return result; | |
| 32 } | |
| 33 | |
| 34 static std::unique_ptr<protocol::Value> serialize(const {{"::".join(config.i
mported.namespace)}}::{{domain.domain}}::API::{{type.id}}* value) | |
| 35 { | |
| 36 auto json = value->toJSONString(); | |
| 37 return SerializedValue::create({{config.imported.from_imported_string %
"std::move(json)"}}); | |
| 38 } | |
| 39 | |
| 40 static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<{{":
:".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}>& valu
e) | |
| 41 { | |
| 42 return serialize(value.get()); | |
| 43 } | |
| 44 }; | |
| 45 {% endfor %} | |
| 46 | |
| 47 {% for namespace in config.protocol.namespace %} | |
| 48 } // namespace {{namespace}} | |
| 49 {% endfor %} | |
| 50 | |
| 51 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imp
orted_h) | |
| OLD | NEW |