OLD | NEW |
1 Protoc compiler Dart plugin | 1 Protoc compiler Dart plugin |
2 =========================== | 2 =========================== |
3 | 3 |
4 This application provides a plugin for protoc compiler which | 4 This application provides a plugin for protoc compiler which |
5 generates pure Dart library to deal with protobufs. | 5 generates pure Dart library to deal with protobufs. |
6 | 6 |
7 Please, do not forget that generated libraries depend on runtime | 7 Please, do not forget that generated libraries depend on runtime |
8 support library which can be found [here](https://github.com/dart-lang/dart-prot
obuf). | 8 support library which can be found [here](https://github.com/dart-lang/dart-prot
obuf). |
9 | 9 |
10 How to build and use | 10 How to build and use |
(...skipping 19 matching lines...) Expand all Loading... |
30 ### Options to control the generated Dart code | 30 ### Options to control the generated Dart code |
31 | 31 |
32 The protocol buffer compiler accepts options for each plugin. For the | 32 The protocol buffer compiler accepts options for each plugin. For the |
33 Dart plugin, these options are passed together with the `--dart_out` | 33 Dart plugin, these options are passed together with the `--dart_out` |
34 option. The individial options are separated using comma, and the | 34 option. The individial options are separated using comma, and the |
35 final output directive is separated from the options using colon. Pass | 35 final output directive is separated from the options using colon. Pass |
36 options `<option 1>` and `<option 2>` like this: | 36 options `<option 1>` and `<option 2>` like this: |
37 | 37 |
38 --dart_out="<option 1>,<option 2>:." | 38 --dart_out="<option 1>,<option 2>:." |
39 | 39 |
40 #### Option for setting the name of field accessors | |
41 | |
42 The following message definition has the field name `has_field`. | |
43 | |
44 message MyMessage { | |
45 optional string has_field = 1; | |
46 } | |
47 | |
48 This poses the problem, that the Dart class will have a getter and a | |
49 setter called `hasField`. This conflicts with the method `hasField` | |
50 which is already defined on the superclass `GeneratedMessage`. | |
51 | |
52 To work around this problem the option `field_name` can be | |
53 used. Option `field_name` takes two values separated by the vertical | |
54 bar. The first value is the full name of the field and the second | |
55 value is the name of the field in the generated Dart code. Passing the | |
56 following option: | |
57 | |
58 --dart_out="field_name=MyMessage.has_field|HasFld:." | |
59 | |
60 Will generate the following message field accessors: | |
61 | |
62 String get hasFld => getField(1); | |
63 void set hasFld(String v) { setField(1, v); } | |
64 bool hasHasFld() => hasField(1); | |
65 void clearHasFld() => clearField(1); | |
66 | |
67 Using protocol buffer libraries to build new libraries | 40 Using protocol buffer libraries to build new libraries |
68 ------------------------------------------------------ | 41 ------------------------------------------------------ |
69 | 42 |
70 The protocol buffer compiler produces one library for each `.proto` file | 43 The protocol buffer compiler produces one library for each `.proto` file |
71 it compiles. In some cases this is not exactly what is needed, e.g one | 44 it compiles. In some cases this is not exactly what is needed, e.g one |
72 would like to create new libraries which exposes the objects in these | 45 would like to create new libraries which exposes the objects in these |
73 libraries or create new librares combining object definitions from | 46 libraries or create new librares combining object definitions from |
74 several `.proto` libraries into one. | 47 several `.proto` libraries into one. |
75 | 48 |
76 The best way to aproach this is to create the new libraries needed and | 49 The best way to aproach this is to create the new libraries needed and |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 $ protoc --plugin=protoc-gen-dart=./plugin --dart_out=. test.proto | 109 $ protoc --plugin=protoc-gen-dart=./plugin --dart_out=. test.proto |
137 | 110 |
138 Useful references | 111 Useful references |
139 ----------------- | 112 ----------------- |
140 | 113 |
141 * [Main Dart site](http://www.dartlang.org) | 114 * [Main Dart site](http://www.dartlang.org) |
142 * [Main protobuf site](https://code.google.com/p/protobuf) | 115 * [Main protobuf site](https://code.google.com/p/protobuf) |
143 * [Protobuf runtime support project](https://github.com/dart-lang/dart-protobuf) | 116 * [Protobuf runtime support project](https://github.com/dart-lang/dart-protobuf) |
144 * [DartEditor download](http://www.dartlang.org) | 117 * [DartEditor download](http://www.dartlang.org) |
145 * [Pub documentation](http://pub.dartlang.org/doc) | 118 * [Pub documentation](http://pub.dartlang.org/doc) |
OLD | NEW |