Skip to content

Commit f1110b0

Browse files
committed
Allow null for optional messages, see #562; Other minor improvements to short ifs
1 parent c079c90 commit f1110b0

23 files changed

+272
-264
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Custom classes are automatically populated with static `encode`, `encodeDelimite
168168

169169
### Using the Reader/Writer interface directly
170170

171-
While meant for the adventurous, it's also possible to use the Reader/Writer interface directly to build custom encoders and decoders that work accross modern to ancient browsers and, of course, node:
171+
While only useful for the adventurous cherishing an aversion to [generated static code](https://github.com/dcodeIO/protobuf.js#command-line), it's also possible to use the Reader/Writer interface directly using just the [minimal runtime](https://github.com/dcodeIO/protobuf.js/tree/master/dist/runtime) to build custom encoders and decoders that work accross modern to ancient browsers and, of course, node:
172172

173173
```js
174174
var writer = protobuf.Writer.create();
@@ -191,7 +191,7 @@ while (reader.pos < reader.len) {
191191
}
192192
```
193193

194-
You can take pretty much any generated code snippet as a reference. Easy ways to obtain these are either setting `protobuf.util.codegen.verbose = true` while watching the magic as it happens, or simply inspecting [generated static code](https://github.com/dcodeIO/protobuf.js#command-line).
194+
Easy ways to obtain example code snippets are either setting `protobuf.util.codegen.verbose = true` while watching the magic as it happens, or simply inspecting generated static code.
195195

196196
### Using services
197197

bench/prof.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var root = protobuf.parse(fs.readFileSync(require.resolve("../bench/bench.proto"
4444
var Test = root.lookup("Test");
4545
var data = require("../bench/bench.json");
4646

47-
var count = process.argv.length > 3 && parseInt(process.argv[3], 10) || 10000000;
47+
var count = process.argv.length > 3 ? parseInt(process.argv[3], 10) : 10000000;
4848

4949
function setupBrowser() {
5050
protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); };

cli/targets/proto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function buildField(field, passExtend) {
178178
else if (field.repeated)
179179
sb.push("repeated", field.type);
180180
else if (syntax === 2)
181-
sb.push(field.required && "required" || "optional", field.type);
181+
sb.push(field.required ? "required" : "optional", field.type);
182182
else
183183
sb.push(field.type);
184184
sb.push(underScore(field.name), "=", field.id);

cli/targets/static.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ function buildService(ref, service) {
407407
push("var requestData;");
408408
push("try {");
409409
++indent;
410-
push("requestData = (this.requestDelimited && $root" + name(method.resolvedRequestType.fullName) + ".encodeDelimited(request) || $root" + name(method.resolvedRequestType.fullName) + ".encode(request)).finish();");
410+
push("requestData = (this.requestDelimited ? $root" + name(method.resolvedRequestType.fullName) + ".encodeDelimited(request) : $root" + name(method.resolvedRequestType.fullName) + ".encode(request)).finish();");
411411
--indent;
412412
push("} catch (err) {");
413413
++indent;
414-
push("(typeof setImmediate === 'function' && setImmediate || setTimeout)(function() { callback(err); });");
414+
push("(typeof setImmediate === 'function' ? setImmediate : setTimeout)(function() { callback(err); });");
415415
push("return;");
416416
--indent;
417417
push("}");
@@ -427,7 +427,7 @@ function buildService(ref, service) {
427427
push("var response;");
428428
push("try {");
429429
++indent;
430-
push("response = self.responseDelimited && $root" + name(method.resolvedResponseType.fullName) + ".decodeDelimited(responseData) || $root" + name(method.resolvedResponseType.fullName) + ".decode(responseData);");
430+
push("response = self.responseDelimited ? $root" + name(method.resolvedResponseType.fullName) + ".decodeDelimited(responseData) : $root" + name(method.resolvedResponseType.fullName) + ".decode(responseData);");
431431
--indent;
432432
push("} catch (err2) {");
433433
++indent;

0 commit comments

Comments
 (0)