Skip to content

Commit

Permalink
Add support for jstype annotation (#104)
Browse files Browse the repository at this point in the history
* Add support for jstype annotation

Required an upgrade to google-protobuf 3.6.1, otherwise very straight forward.

Fixes #17

* Add test coverage for all support field types
  • Loading branch information
Jonny Reeves authored Sep 1, 2018
1 parent 50bb30c commit 24fbad6
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,12 @@ client.getUser(req, (err, user) => { /* ... */ });
For a sample of the generated protos and service definitions, see [examples](https://github.com/improbable-eng/ts-protoc-gen/tree/master/examples).

To generate the examples from protos, please run `./generate.sh`

## Gotchas
By default the google-protobuf library will use the JavaScript number type to store 64bit float and integer values; this can lead to overflow problems as you exceed JavaScript's `Number.MAX_VALUE`. To work around this, you should consider using the `jstype` annotation on any 64bit fields, ie:

```proto
message Example {
uint64 bigInt = 1 [jstype = JS_STRING];
}
```
41 changes: 41 additions & 0 deletions examples/generated/proto/examplecom/annotations_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

265 changes: 265 additions & 0 deletions examples/generated/proto/examplecom/annotations_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/generated/proto/examplecom/annotations_pb_service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "Improbable",
"license": "Apache-2.0",
"dependencies": {
"google-protobuf": "^3.5.0"
"google-protobuf": "^3.6.1"
},
"devDependencies": {
"@types/chai": "^3.5.2",
Expand Down
11 changes: 11 additions & 0 deletions proto/examplecom/annotations.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package examplecom;

message AnnotatedMessage {
uint64 myUnit64 = 1 [jstype = JS_STRING];
int64 myInt64 = 2 [jstype = JS_STRING];
fixed64 myFixed64 = 3 [jstype = JS_STRING];
sint64 mySint64 = 4 [jstype = JS_STRING];
sfixed64 mySfixed64 = 5 [jstype = JS_STRING];
}
Loading

0 comments on commit 24fbad6

Please sign in to comment.