OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 interface ProtobufContainer { |
| 6 String get fqname(); |
| 7 String get classname(); |
| 8 GoogleProtobuf_FileOptions_OptimizeMode get optimizeFor(); |
| 9 } |
| 10 |
| 11 class CodeGenerator implements ProtobufContainer { |
| 12 CodeGenerator(ProtocGenDartConfig this._config, InputStream this._streamIn, |
| 13 OutputStream this._streamOut, OutputStream this._streamErr); |
| 14 |
| 15 void generate() { |
| 16 PbInputStreamReader reader = new PbInputStreamReader(_streamIn); |
| 17 Future<List<int>> futureBytes = reader.readBytes(); |
| 18 futureBytes.then(_(List<int> bytes) { |
| 19 _streamIn.close(); |
| 20 GoogleProtobufCompiler_CodeGeneratorRequest request = |
| 21 GoogleProtobufCompiler_CodeGeneratorRequest.parseFromBuffer(bytes); |
| 22 |
| 23 GoogleProtobufCompiler_CodeGeneratorResponse_Builder responseBuilder = |
| 24 new GoogleProtobufCompiler_CodeGeneratorResponse_Builder(); |
| 25 |
| 26 GenerationContext ctx = |
| 27 new GenerationContext(new OutputStreamWriter(_streamErr)); |
| 28 |
| 29 List<FileGenerator> generators = new List<FileGenerator>(); |
| 30 for (GoogleProtobuf_FileDescriptorProto file in request.protoFile) { |
| 31 FileGenerator generator = new FileGenerator(file, this, ctx); |
| 32 if (request.fileToGenerate.indexOf(file.name) >= 0) { |
| 33 generators.add(generator); |
| 34 } |
| 35 } |
| 36 |
| 37 for (FileGenerator filegen in generators) { |
| 38 GoogleProtobufCompiler_CodeGeneratorResponse_File file = filegen.generat
e(); |
| 39 responseBuilder.file.add(file); |
| 40 } |
| 41 |
| 42 List<int> buffer = responseBuilder.build().writeToBuffer(); |
| 43 _streamOut.write(buffer); |
| 44 }); |
| 45 } |
| 46 |
| 47 ProtocGenDartConfig _config; |
| 48 InputStream _streamIn; |
| 49 OutputStream _streamOut; |
| 50 OutputStream _streamErr; |
| 51 GoogleProtobuf_FileOptions_OptimizeMode get optimizeFor() => null; |
| 52 String get fqname() => ""; |
| 53 String get classname() => null; |
| 54 } |
OLD | NEW |