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

Side by Side Diff: README.md

Issue 23536028: Added documentation on building other libraries using generated libraries (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 --dart_out="field_name=MyMessage.has_field|HasFld:." 58 --dart_out="field_name=MyMessage.has_field|HasFld:."
59 59
60 Will generate the following message field accessors: 60 Will generate the following message field accessors:
61 61
62 String get hasFld => getField(1); 62 String get hasFld => getField(1);
63 void set hasFld(String v) { setField(1, v); } 63 void set hasFld(String v) { setField(1, v); }
64 bool hasHasFld() => hasField(1); 64 bool hasHasFld() => hasField(1);
65 void clearHasFld() => clearField(1); 65 void clearHasFld() => clearField(1);
66 66
67 Using protocol buffer libraries to build new libraries
68 ------------------------------------------------------
69
70 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
72 would like to create new libraries which exposes the objects in these
73 libraries or create new librares combining object definitions from
74 several `.proto` libraries into one.
75
76 The best way to aproach this is to create the new libraries needed and
77 re-export the relevant protocol buffer classes.
78
79 Say we have the file `m1.proto` with the following content
80
81 message M1 {
82 optional string a;
83 }
84
85 and `m2.proto` containing
86
87 message M2 {
88 optional string b;
89 }
90
91 Compiling these to Dart will produce two libraries in `m1.pb.dart` and
92 `m2.pb.dart`. The following code shows a library M which combines
93 these two protocol buffer libraries, exposes the classes `M1` and `M2` and
94 adds som additional methods.
95
96 library M;
97
98 import "m1.pb.dart";
99 import "m2.pb.dart";
100
101 export "m1.pb.dart" show M1;
102 export "m2.pb.dart" show M2;
103
104 M1 createM1() => new M1();
105 M2 createM2() => new M2();
106
67 Hacking 107 Hacking
68 ------- 108 -------
69 109
70 Remember to run the tests. That is as easy as `make run-tests`. 110 Remember to run the tests. That is as easy as `make run-tests`.
71 111
72 The default way of running the Dart protoc plugin is through the 112 The default way of running the Dart protoc plugin is through the
73 generated `out/protoc-gen-dart` script. However when run this way the 113 generated `out/protoc-gen-dart` script. However when run this way the
74 Dart code is assembled into one large Dart file using dart2dart. To 114 Dart code is assembled into one large Dart file using dart2dart. To
75 run with the actual source in the repository create an executable 115 run with the actual source in the repository create an executable
76 script called `protoc-gen-dart` with the following content: 116 script called `protoc-gen-dart` with the following content:
(...skipping 14 matching lines...) Expand all
91 $ protoc --plugin=protoc-gen-dart=./plugin --dart_out=. test.proto 131 $ protoc --plugin=protoc-gen-dart=./plugin --dart_out=. test.proto
92 132
93 Useful references 133 Useful references
94 ----------------- 134 -----------------
95 135
96 * [Main Dart site](http://www.dartlang.org) 136 * [Main Dart site](http://www.dartlang.org)
97 * [Main protobuf site](https://code.google.com/p/protobuf) 137 * [Main protobuf site](https://code.google.com/p/protobuf)
98 * [Protobuf runtime support project](https://github.com/dart-lang/dart-protobuf) 138 * [Protobuf runtime support project](https://github.com/dart-lang/dart-protobuf)
99 * [DartEditor download](http://www.dartlang.org) 139 * [DartEditor download](http://www.dartlang.org)
100 * [Pub documentation](http://pub.dartlang.org/doc) 140 * [Pub documentation](http://pub.dartlang.org/doc)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698