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

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: 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 = (parent.classname == '')
20 ? descriptor.name
21 : '${parent.classname}_${descriptor.name}',
Søren Gjesse 2015/06/23 12:08:31 Can services be nested? If so please add a test fo
wibling 2015/06/23 13:26:34 No, I have simplified this to just descriptor.name
22 fqname = (parent == null || parent.fqname == null)
23 ? descriptor.name
24 : (parent.fqname == '.'
25 ? '.${descriptor.name}'
26 : '${parent.fqname}.${descriptor.name}') {
27 _context.register(this);
28 }
29
30 String get package => _parent.package;
31
32 String _shortType(String typename) {
33 return typename.substring(typename.lastIndexOf('.')+1);
34 }
35
36 void generate(IndentingWriter out) {
37 out.addBlock('class ${classname}Api {', '}', () {
38 out.println('ProtobufClient _client;');
39 out.println('${classname}Api(this._client);');
40 out.println();
41 for (MethodDescriptorProto m in _descriptor.method) {
42 out.addBlock('Future<${_shortType(m.outputType)}> ${m.name}('
43 '${_shortType(m.inputType)} request) '
44 'async {', '}', () {
45 out.println(
46 'var resultBytes = await _client.Invoke(\'/${_descriptor.name}.'
47 '${m.name}\', request.writeToBuffer());');
48 out.println('return new ${_shortType(m.outputType)}'
49 '.fromBuffer(resultBytes);');
50 });
51 }
52 });
53 out.println();
54 }
55 }
OLDNEW
« no previous file with comments | « Makefile ('k') | lib/file_generator.dart » ('j') | lib/file_generator.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698