Permalink
Browse files

Allow null for optional messages, see #562; Other minor improvements …

…to short ifs
  • Loading branch information...
dcodeIO committed Dec 15, 2016
1 parent c079c90 commit f1110b0993ec86e0a4aee1735bd75b901952cb36
@@ -168,7 +168,7 @@ Custom classes are automatically populated with static `encode`, `encodeDelimite
### Using the Reader/Writer interface directly
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:
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:
```js
var writer = protobuf.Writer.create();
@@ -191,7 +191,7 @@ while (reader.pos < reader.len) {
}
```
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).
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.
### Using services
@@ -44,7 +44,7 @@ var root = protobuf.parse(fs.readFileSync(require.resolve("../bench/bench.proto"
var Test = root.lookup("Test");
var data = require("../bench/bench.json");
var count = process.argv.length > 3 && parseInt(process.argv[3], 10) || 10000000;
var count = process.argv.length > 3 ? parseInt(process.argv[3], 10) : 10000000;
function setupBrowser() {
protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); };
@@ -178,7 +178,7 @@ function buildField(field, passExtend) {
else if (field.repeated)
sb.push("repeated", field.type);
else if (syntax === 2)
sb.push(field.required && "required" || "optional", field.type);
sb.push(field.required ? "required" : "optional", field.type);
else
sb.push(field.type);
sb.push(underScore(field.name), "=", field.id);
@@ -407,11 +407,11 @@ function buildService(ref, service) {
push("var requestData;");
push("try {");
++indent;
push("requestData = (this.requestDelimited && $root" + name(method.resolvedRequestType.fullName) + ".encodeDelimited(request) || $root" + name(method.resolvedRequestType.fullName) + ".encode(request)).finish();");
push("requestData = (this.requestDelimited ? $root" + name(method.resolvedRequestType.fullName) + ".encodeDelimited(request) : $root" + name(method.resolvedRequestType.fullName) + ".encode(request)).finish();");
--indent;
push("} catch (err) {");
++indent;
push("(typeof setImmediate === 'function' && setImmediate || setTimeout)(function() { callback(err); });");
push("(typeof setImmediate === 'function' ? setImmediate : setTimeout)(function() { callback(err); });");
push("return;");
--indent;
push("}");
@@ -427,7 +427,7 @@ function buildService(ref, service) {
push("var response;");
push("try {");
++indent;
push("response = self.responseDelimited && $root" + name(method.resolvedResponseType.fullName) + ".decodeDelimited(responseData) || $root" + name(method.resolvedResponseType.fullName) + ".decode(responseData);");
push("response = self.responseDelimited ? $root" + name(method.resolvedResponseType.fullName) + ".decodeDelimited(responseData) : $root" + name(method.resolvedResponseType.fullName) + ".decode(responseData);");
--indent;
push("} catch (err2) {");
++indent;
Oops, something went wrong.

0 comments on commit f1110b0

Please sign in to comment.