Skip to content

Commit bfac0ea

Browse files
committed
Stripped out fallback encoder/decoder/verifier completely (even IE8 supports codegen), significantly reduces bundle size, can use static codegen elsewhere
1 parent c234de7 commit bfac0ea

22 files changed

+185
-884
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ While .proto and JSON files require the full library (about 18kb gzipped), prett
402402

403403
Static code, on the other hand, requires just the minimal runtime (about 5.5kb gzipped), but generates additional, albeit editable, source code without any reflection features.
404404

405-
Where `new Function(...)` is supported (it usually is), there is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.
405+
There is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.
406406

407407
Building
408408
--------
@@ -493,8 +493,6 @@ Note that JSON is a native binding nowadays and as such is about as fast as it p
493493
* For entirely bogus values encoders intentionally rely on runtime errors to be thrown somewhere down the road.
494494
* Quite a bit of V8-specific profiling is accountable for everything else.
495495

496-
Note that code generation requires `new Function(...)` (basically `eval`) support and that an equivalent but slower fallback will be used where unsupported.
497-
498496
You can also run [the benchmark](https://github.com/dcodeIO/protobuf.js/blob/master/bench/index.js) ...
499497

500498
```

cli/targets/static.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function buildType(ref, type) {
282282
"@param {Writer} [writer] Writer to encode to",
283283
"@returns {Writer} Writer"
284284
]);
285-
buildFunction(type, "encode", protobuf.encode.generate(type), {
285+
buildFunction(type, "encode", protobuf.encoder(type), {
286286
Writer : "$protobuf.Writer",
287287
util : "$protobuf.util"
288288
});
@@ -318,7 +318,7 @@ function buildType(ref, type) {
318318
"@param {number} [length] Message length if known beforehand",
319319
"@returns {" + fullName + "} " + type.name
320320
]);
321-
buildFunction(type, "decode", protobuf.decode.generate(type), {
321+
buildFunction(type, "decode", protobuf.decoder(type), {
322322
Reader : "$protobuf.Reader",
323323
util : "$protobuf.util"
324324
});
@@ -351,7 +351,7 @@ function buildType(ref, type) {
351351
"@param {" + fullName + "|Object} message " + type.name + " or plain object to verify",
352352
"@returns {?string} `null` if valid, otherwise the reason why it is not"
353353
]);
354-
buildFunction(type, "verify", protobuf.verify.generate(type), {
354+
buildFunction(type, "verify", protobuf.verifier(type), {
355355
util : "$protobuf.util"
356356
});
357357

0 commit comments

Comments
 (0)