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

Unified Diff: lib/protobuf/plugin/CodeGenerator.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/fixnum/int64.dart ('k') | lib/protobuf/plugin/DartFile.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/plugin/CodeGenerator.dart
diff --git a/lib/protobuf/plugin/CodeGenerator.dart b/lib/protobuf/plugin/CodeGenerator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d122feefac0a2f0782272b6cf66b88b3d65cb00d
--- /dev/null
+++ b/lib/protobuf/plugin/CodeGenerator.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+interface ProtobufContainer {
+ String get fqname();
+ String get classname();
+ GoogleProtobuf_FileOptions_OptimizeMode get optimizeFor();
+}
+
+class CodeGenerator implements ProtobufContainer {
+ CodeGenerator(ProtocGenDartConfig this._config, InputStream this._streamIn,
+ OutputStream this._streamOut, OutputStream this._streamErr);
+
+ void generate() {
+ PbInputStreamReader reader = new PbInputStreamReader(_streamIn);
+ Future<List<int>> futureBytes = reader.readBytes();
+ futureBytes.then(_(List<int> bytes) {
+ _streamIn.close();
+ GoogleProtobufCompiler_CodeGeneratorRequest request =
+ GoogleProtobufCompiler_CodeGeneratorRequest.parseFromBuffer(bytes);
+
+ GoogleProtobufCompiler_CodeGeneratorResponse_Builder responseBuilder =
+ new GoogleProtobufCompiler_CodeGeneratorResponse_Builder();
+
+ GenerationContext ctx =
+ new GenerationContext(new OutputStreamWriter(_streamErr));
+
+ List<FileGenerator> generators = new List<FileGenerator>();
+ for (GoogleProtobuf_FileDescriptorProto file in request.protoFile) {
+ FileGenerator generator = new FileGenerator(file, this, ctx);
+ if (request.fileToGenerate.indexOf(file.name) >= 0) {
+ generators.add(generator);
+ }
+ }
+
+ for (FileGenerator filegen in generators) {
+ GoogleProtobufCompiler_CodeGeneratorResponse_File file = filegen.generate();
+ responseBuilder.file.add(file);
+ }
+
+ List<int> buffer = responseBuilder.build().writeToBuffer();
+ _streamOut.write(buffer);
+ });
+ }
+
+ ProtocGenDartConfig _config;
+ InputStream _streamIn;
+ OutputStream _streamOut;
+ OutputStream _streamErr;
+ GoogleProtobuf_FileOptions_OptimizeMode get optimizeFor() => null;
+ String get fqname() => "";
+ String get classname() => null;
+}
« no previous file with comments | « lib/fixnum/int64.dart ('k') | lib/protobuf/plugin/DartFile.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698