Skip to content

Commit

Permalink
New: decode throws specific ProtocolError with a reference to the so …
Browse files Browse the repository at this point in the history
…far decoded message if required fields are missing + example
  • Loading branch information
dcodeIO committed Mar 6, 2017
1 parent 13e4aa3 commit 26d9fad
Show file tree
Hide file tree
Showing 24 changed files with 399 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protobuf.load("awesome.proto", function(err, root) {
});
```

**Note:** To avoid redundant assertions where messages are already known to be valid, there is a seperate method for encoding and verification. Hence ...
**Note:** To avoid redundant assertions where messages are already known to be valid, there is a separate method for encoding and verification.

* `Message.encode` does not implicitly verify a message but tries to encode whatever is specified, possibly resulting in a runtime error being thrown somewhere down the road.
* `Message.verify` can be used to explicitly perform verification prior to encoding where necessary. Instead of throwing, it returns the error message, if any.
Expand Down
6 changes: 4 additions & 2 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ function buildType(ref, type) {
"@param {$protobuf.Reader|Uint8Array} " + (config.beautify ? "reader" : "r") + " Reader or buffer to decode from",
"@param {number} [" + (config.beautify ? "length" : "l") + "] Message length if known beforehand",
"@returns {" + fullName + "} " + type.name,
"@throws {Error} If the payload is not a reader or valid buffer or required fields are missing"
"@throws {Error} If the payload is not a reader or valid buffer",
"@throws {$protobuf.util.ProtocolError} If required fields are missing"
]);
buildFunction(type, "decode", protobuf.decoder(type));

Expand All @@ -435,7 +436,8 @@ function buildType(ref, type) {
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer, length delimited.",
"@param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from",
"@returns {" + fullName + "} " + type.name,
"@throws {Error} If the payload is not a reader or valid buffer or required fields are missing"
"@throws {Error} If the payload is not a reader or valid buffer",
"@throws {$protobuf.util.ProtocolError} If required fields are missing"
]);
push(name(type.name) + ".decodeDelimited = function decodeDelimited(reader) {");
++indent;
Expand Down
101 changes: 79 additions & 22 deletions dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/light/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 26d9fad

Please sign in to comment.