OLD | NEW |
---|---|
(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 } | |
OLD | NEW |