Permalink
Browse files

New: decode throws specific ProtocolError with a reference to the so …

…far decoded message if required fields are missing + example
  • Loading branch information...
dcodeIO committed Mar 6, 2017
1 parent 13e4aa3 commit 26d9fadb21a85ca0b5609156c26453ae875e4933
@@ -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.
@@ -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));

@@ -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;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +106 Bytes (100%) dist/light/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 26d9fad

Please sign in to comment.