| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """protoc plugin to create c++ reader/writer for json-encoded protobufs | 6 """protoc plugin to create c++ reader/writer for json-encoded protobufs |
| 7 | 7 |
| 8 The reader/writer use Chrome's base::Values. | 8 The reader/writer use Chrome's base::Values. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 for field_proto in message.GetFields(): | 78 for field_proto in message.GetFields(): |
| 79 self.WriteFieldRead(field_proto) | 79 self.WriteFieldRead(field_proto) |
| 80 | 80 |
| 81 self.Output( | 81 self.Output( |
| 82 ' return true;\n' | 82 ' return true;\n' |
| 83 '\n' | 83 '\n' |
| 84 'error:\n' | 84 'error:\n' |
| 85 ' return false;\n' | 85 ' return false;\n' |
| 86 '}}\n' | 86 '}}\n' |
| 87 '\n' | 87 '\n' |
| 88 'static scoped_ptr<base::Value> WriteToValue(const {generated_class_na
me}& message) {{\n' | 88 'static scoped_ptr<base::DictionaryValue> WriteToValue(const {generate
d_class_name}& message) {{\n' |
| 89 ' scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue())
;\n' | 89 ' scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue())
;\n' |
| 90 '', | 90 '', |
| 91 generated_class_name=generated_class_name) | 91 generated_class_name=generated_class_name) |
| 92 | 92 |
| 93 with self.AddIndent(): | 93 with self.AddIndent(): |
| 94 for field_proto in message.GetFields(): | 94 for field_proto in message.GetFields(): |
| 95 self.FieldWriteToValue(field_proto) | 95 self.FieldWriteToValue(field_proto) |
| 96 | 96 |
| 97 self.Output( | 97 self.Output( |
| 98 ' return dict.Pass();\n' | 98 ' return dict;\n' |
| 99 '', | 99 '', |
| 100 generated_class_name=generated_class_name) | 100 generated_class_name=generated_class_name) |
| 101 self.Output('}}') | 101 self.Output('}}') |
| 102 | 102 |
| 103 self.Output('}};') | 103 self.Output('}};') |
| 104 self.Output('') | 104 self.Output('') |
| 105 | 105 |
| 106 def FieldWriteToValue(self, field): | 106 def FieldWriteToValue(self, field): |
| 107 if field.IsRepeated(): | 107 if field.IsRepeated(): |
| 108 self.Output('{{') | 108 self.Output('{{') |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 response.AddFileWithContent(converter_filename, writer.GetValue()) | 264 response.AddFileWithContent(converter_filename, writer.GetValue()) |
| 265 if writer.GetErrors(): | 265 if writer.GetErrors(): |
| 266 response.AddError('\n'.join(writer.GetErrors())) | 266 response.AddError('\n'.join(writer.GetErrors())) |
| 267 | 267 |
| 268 response.WriteToStdout() | 268 response.WriteToStdout() |
| 269 | 269 |
| 270 | 270 |
| 271 if __name__ == '__main__': | 271 if __name__ == '__main__': |
| 272 main() | 272 main() |
| OLD | NEW |