Skip to content

Commit 26d9fad

Browse files
committed
New: decode throws specific ProtocolError with a reference to the so far decoded message if required fields are missing + example
1 parent 13e4aa3 commit 26d9fad

24 files changed

+399
-82
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protobuf.load("awesome.proto", function(err, root) {
133133
});
134134
```
135135

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

138138
* `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.
139139
* `Message.verify` can be used to explicitly perform verification prior to encoding where necessary. Instead of throwing, it returns the error message, if any.

cli/targets/static.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ function buildType(ref, type) {
425425
"@param {$protobuf.Reader|Uint8Array} " + (config.beautify ? "reader" : "r") + " Reader or buffer to decode from",
426426
"@param {number} [" + (config.beautify ? "length" : "l") + "] Message length if known beforehand",
427427
"@returns {" + fullName + "} " + type.name,
428-
"@throws {Error} If the payload is not a reader or valid buffer or required fields are missing"
428+
"@throws {Error} If the payload is not a reader or valid buffer",
429+
"@throws {$protobuf.util.ProtocolError} If required fields are missing"
429430
]);
430431
buildFunction(type, "decode", protobuf.decoder(type));
431432

@@ -435,7 +436,8 @@ function buildType(ref, type) {
435436
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer, length delimited.",
436437
"@param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from",
437438
"@returns {" + fullName + "} " + type.name,
438-
"@throws {Error} If the payload is not a reader or valid buffer or required fields are missing"
439+
"@throws {Error} If the payload is not a reader or valid buffer",
440+
"@throws {$protobuf.util.ProtocolError} If required fields are missing"
439441
]);
440442
push(name(type.name) + ".decodeDelimited = function decodeDelimited(reader) {");
441443
++indent;

dist/light/protobuf.js

Lines changed: 79 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/light/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/light/protobuf.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/light/protobuf.min.js.gz

106 Bytes
Binary file not shown.

dist/light/protobuf.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)