https://github.com/edvardchen/node_protoc2
Compile 64-int types to string when generating static code for protobuf in JavaScript
https://github.com/edvardchen/node_protoc2
nodejs protobuf protoc
Last synced: about 1 month ago
JSON representation
Compile 64-int types to string when generating static code for protobuf in JavaScript
- Host: GitHub
- URL: https://github.com/edvardchen/node_protoc2
- Owner: edvardchen
- License: apache-2.0
- Created: 2021-03-17T12:02:50.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-08T08:39:25.000Z (about 5 years ago)
- Last Synced: 2025-10-09T18:05:17.593Z (8 months ago)
- Topics: nodejs, protobuf, protoc
- Language: TypeScript
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# node_protoc2
Wrap [grpc-tools](https://github.com/grpc/grpc-node/tree/master/packages/grpc-tools) with additional ability that compile protobuf 64-int types to string automatically
## Why
The [official](https://developers.google.com/protocol-buffers/docs/proto#scalar) table that shows the type specified in the `.proto` file and the corresponding type in target program language doesn't include the JavaScript example. So here is:
| .proto Type | JavaScript |
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| double, float, int32,uint32,sint32,fixed32,sfixed32 | number |
| int64,uint64,sint64,fixed64,sfixed64 | number (maybe overflow) |
| bool | boolean |
| string | string |
| byte | [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) |
By default the official compiler `protoc` will compile all protobuf `64-int` types into the JavaScript number type that maybe would cause overflow.
To work around this, you need to adding `jstype` annotation for every `64-int` field because `protoc` doesn't provide any global compile option. Somehow this is annoying when the `.proto` files are not maintained by other teams.
So, I wrote this tool to make it easy.
## Usage
You can generate static codes in JavaScript from `.proto` files through the following command:
```bash
npx node_protoc2 --out_dir output_folder foo.proto
```
All proto `64-int` types would be compiled into JavaScript `string` type