def _test_message(self, message: Descriptor): table_resolver = TableResolver() analyzer = Analyzer(table_resolver) analyzer.generate_tables_for_file(self._create_file_with_message(message)) result = list(table_resolver.tables) self.assertTrue(len(result) is 1) result_table: Table = result[0] # Sort the fields by name. def sorted_by_fields_name(fields): return fields.sort(key=lambda field: field.name) for table_field, message_field in zip(sorted_by_fields_name(result_table.fields), sorted_by_fields_name(message.fields)): self._test_field(table_field, message_field)
def main(): # Read request message from stdin data = sys.stdin.buffer.read() # Parse request request = plugin.CodeGeneratorRequest() request.ParseFromString(data) # Create response response = plugin.CodeGeneratorResponse() # TODO: clean this part. # Generate code table_resolver = TableResolver() analyzer = Analyzer(table_resolver) pool = DescriptorPool() for proto_file in request.proto_file: pool.Add(proto_file) analyzer.generate_tables_for_file( file_descriptor=pool.FindFileByName(proto_file.name)) analyzer.link_tables_references() writer = ProtoPluginResponseWriter() writer.write(generator=KotlinExposedGenerator(), tables=table_resolver.tables, plugin_response=response) # Serialise response message output = response.SerializeToString() # Write to stdout sys.stdout.buffer.write(output)