Skip to content

Commit

Permalink
Allow null for optional messages, see #562; Other minor improvements …
Browse files Browse the repository at this point in the history
…to short ifs
  • Loading branch information
dcodeIO committed Dec 15, 2016
1 parent c079c90 commit f1110b0
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 264 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bench/prof.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); };
Expand Down
2 changes: 1 addition & 1 deletion cli/targets/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("}");
Expand All @@ -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;
Expand Down
Loading

0 comments on commit f1110b0

Please sign in to comment.