Skip to content

Commit

Permalink
Other: Slightly restructured utility to better support static code de…
Browse files Browse the repository at this point in the history
…fault values
  • Loading branch information
dcodeIO committed Jan 7, 2017
1 parent 1154ce0 commit 1e6a8d1
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 373 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,19 @@ There is no difference performance-wise as the code generated statically is pret

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

1. Always use `SomeMessage.create(...)` instead of `new SomeMessage(...)` because reflection does not provide such a constructor.
2. Types, services and enums must start with an uppercase letter to become available on the reflected types as well.
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).
1. Use `SomeMessage.create(...)` instead of `new SomeMessage(...)` (reflection does not provide such a constructor).
2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well.
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).

Building
--------

To build the library or its components yourself, clone it from GitHub and install the development
dependencies:
To build the library or its components yourself, clone it from GitHub and install the development dependencies:

```
$> git clone https://github.com/dcodeIO/protobuf.js.git
$> cd protobuf.js
$> npm install --dev
$> npm install
```

Building the development and production versions with their respective source maps to `dist/`:
Expand Down
12 changes: 8 additions & 4 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,14 @@ function buildType(ref, type) {
else if (field.map)
push("$prototype" + prop + " = $protobuf.util.emptyObject;");
else if (field.long)
push("$prototype" + prop + " = $protobuf.util.Long ? $protobuf.util.Long.fromValue(" + JSON.stringify(field.typeDefault) + ") : " + field.typeDefault.toNumber(field.type.charAt(0) === "u") + ";");
else if (field.bytes)
push("$prototype" + prop + " = " + JSON.stringify(Array.prototype.slice.call(field.typeDefault)) + ";");
else
push("$prototype" + prop + " = $protobuf.util.Long ? $protobuf.util.Long.fromBits("
+ JSON.stringify(field.typeDefault.low) + ","
+ JSON.stringify(field.typeDefault.high) + ","
+ JSON.stringify(field.typeDefault.unsigned)
+ ") : " + field.typeDefault.toNumber(field.type.charAt(0) === "u") + ";");
else if (field.bytes) {
push("$prototype" + prop + " = $protobuf.util.newBuffer(" + JSON.stringify(Array.prototype.slice.call(field.typeDefault)) + ");");
} else
push("$prototype" + prop + " = " + JSON.stringify(field.typeDefault) + ";");
});

Expand Down
163 changes: 86 additions & 77 deletions dist/noparse/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/noparse/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/noparse/protobuf.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading

0 comments on commit 1e6a8d1

Please sign in to comment.