Skip to content

Commit 1e6a8d1

Browse files
committed
Other: Slightly restructured utility to better support static code default values
1 parent 1154ce0 commit 1e6a8d1

25 files changed

+420
-373
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,19 @@ There is no difference performance-wise as the code generated statically is pret
432432

433433
Additionally, JSON modules can be used with TypeScript definitions generated for their static counterparts as long as the following conditions are met:
434434

435-
1. Always use `SomeMessage.create(...)` instead of `new SomeMessage(...)` because reflection does not provide such a constructor.
436-
2. Types, services and enums must start with an uppercase letter to become available on the reflected types as well.
437-
3. When using a TypeScript definition with code not generated by pbjs, `resolveAll()` must be called once on the root instance to populate these additional properties (JSON modules do this automatically).
435+
1. Use `SomeMessage.create(...)` instead of `new SomeMessage(...)` (reflection does not provide such a constructor).
436+
2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well.
437+
3. When using a TypeScript definition with custom code, `resolveAll()` must be called once on the root instance to populate these additional properties (JSON modules do this automatically).
438438

439439
Building
440440
--------
441441

442-
To build the library or its components yourself, clone it from GitHub and install the development
443-
dependencies:
442+
To build the library or its components yourself, clone it from GitHub and install the development dependencies:
444443

445444
```
446445
$> git clone https://github.com/dcodeIO/protobuf.js.git
447446
$> cd protobuf.js
448-
$> npm install --dev
447+
$> npm install
449448
```
450449

451450
Building the development and production versions with their respective source maps to `dist/`:

cli/targets/static.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,14 @@ function buildType(ref, type) {
283283
else if (field.map)
284284
push("$prototype" + prop + " = $protobuf.util.emptyObject;");
285285
else if (field.long)
286-
push("$prototype" + prop + " = $protobuf.util.Long ? $protobuf.util.Long.fromValue(" + JSON.stringify(field.typeDefault) + ") : " + field.typeDefault.toNumber(field.type.charAt(0) === "u") + ";");
287-
else if (field.bytes)
288-
push("$prototype" + prop + " = " + JSON.stringify(Array.prototype.slice.call(field.typeDefault)) + ";");
289-
else
286+
push("$prototype" + prop + " = $protobuf.util.Long ? $protobuf.util.Long.fromBits("
287+
+ JSON.stringify(field.typeDefault.low) + ","
288+
+ JSON.stringify(field.typeDefault.high) + ","
289+
+ JSON.stringify(field.typeDefault.unsigned)
290+
+ ") : " + field.typeDefault.toNumber(field.type.charAt(0) === "u") + ";");
291+
else if (field.bytes) {
292+
push("$prototype" + prop + " = $protobuf.util.newBuffer(" + JSON.stringify(Array.prototype.slice.call(field.typeDefault)) + ");");
293+
} else
290294
push("$prototype" + prop + " = " + JSON.stringify(field.typeDefault) + ";");
291295
});
292296

dist/noparse/protobuf.js

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

dist/noparse/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/noparse/protobuf.min.js

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

dist/noparse/protobuf.min.js.gz

29 Bytes
Binary file not shown.

dist/noparse/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)