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

Side by Side Diff: lib/client_generator.dart

Issue 1196293003: Initial support for generating client and server stubs for Dart. (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: don't import dart:async if no services Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 part of protoc;
6
7 class ClientApiGenerator extends ProtobufContainer {
8 final String classname;
9 final String fqname;
10
11 final ProtobufContainer _parent;
12 final GenerationContext _context;
13 final ServiceDescriptorProto _descriptor;
14
15 ClientApiGenerator(ServiceDescriptorProto descriptor,
16 ProtobufContainer parent, this._context)
17 : _descriptor = descriptor,
18 _parent = parent,
19 classname = descriptor.name,
20 fqname = (parent == null || parent.fqname == null)
21 ? descriptor.name
22 : (parent.fqname == '.'
23 ? '.${descriptor.name}'
24 : '${parent.fqname}.${descriptor.name}') {
25 _context.register(this);
26 }
27
28 String get package => _parent.package;
29
30 String _shortType(String typename) {
31 return typename.substring(typename.lastIndexOf('.')+1);
32 }
33
34 void generate(IndentingWriter out) {
35 out.addBlock('class ${classname}Api {', '}', () {
36 out.println('ProtobufClient _client;');
Søren Gjesse 2015/06/24 09:08:02 We could just make this 'var' then the class name
37 out.println('${classname}Api(this._client);');
38 out.println();
39 for (MethodDescriptorProto m in _descriptor.method) {
40 out.addBlock('Future<${_shortType(m.outputType)}> ${m.name}('
41 'ClientContext ctx, ${_shortType(m.inputType)} request) '
42 'async {', '}', () {
43 out.println(
44 'var resultBytes = await _client.Invoke(ctx, '
45 '\'/${_descriptor.name}.${m.name}\', request.writeToBuffer());');
skybrian 2015/06/24 16:16:29 It seems like ProtobufClient should have the respo
46 out.println('return new ${_shortType(m.outputType)}'
47 '.fromBuffer(resultBytes);');
48 });
49 }
50 });
51 out.println();
52 }
53 }
OLDNEW
« no previous file with comments | « Makefile ('k') | lib/file_generator.dart » ('j') | lib/indenting_writer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698