Skip to content

Commit 4c0a21f

Browse files
committed
fix bigint deserialization and update readme
1 parent 68c3d24 commit 4c0a21f

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<p align="center">
33
<a href="https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/test.yml?branch=master&label=build&logo=github" alt=""></a>
44
<a href="https://github.com/protobufjs/protobuf.js/actions/workflows/release.yaml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/release.yaml?branch=master&label=release&logo=github" alt=""></a>
5-
<a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg?logo=npm" alt=""></a>
6-
<a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg?label=downloads&logo=npm" alt=""></a>
7-
<a href="https://www.jsdelivr.com/package/npm/protobufjs"><img src="https://img.shields.io/jsdelivr/npm/hm/protobufjs?label=requests&logo=jsdelivr" alt=""></a>
5+
<a href="https://npmjs.org/package/@tanglechat/protobufjs"><img src="https://img.shields.io/npm/v/@tanglechat/protobufjs.svg?logo=npm" alt=""></a>
6+
<a href="https://npmjs.org/package/@tanglechat/protobufjs"><img src="https://img.shields.io/npm/dm/@tanglechat/protobufjs.svg?label=downloads&logo=npm" alt=""></a>
7+
<a href="https://www.jsdelivr.com/package/npm/@tanglechat/protobufjs"><img src="https://img.shields.io/jsdelivr/npm/hm/@tanglechat/protobufjs?label=requests&logo=jsdelivr" alt=""></a>
88
</p>
99

1010
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://protobuf.dev/)).
@@ -51,39 +51,39 @@ Installation
5151
### Node.js
5252

5353
```sh
54-
npm install protobufjs --save
54+
npm install @tanglechat/protobufjs --save
5555
```
5656

5757
```js
5858
// Static code + Reflection + .proto parser
59-
var protobuf = require("protobufjs");
59+
var protobuf = require("@tanglechat/protobufjs");
6060

6161
// Static code + Reflection
62-
var protobuf = require("protobufjs/light");
62+
var protobuf = require("@tanglechat/protobufjs/light");
6363

6464
// Static code only
65-
var protobuf = require("protobufjs/minimal");
65+
var protobuf = require("@tanglechat/protobufjs/minimal");
6666
```
6767

68-
The optional [command line utility](./cli/) to generate static code and reflection bundles lives in the `protobufjs-cli` package and can be installed separately:
68+
The optional [command line utility](./cli/) to generate static code and reflection bundles lives in the `@tanglechat/protobufjs-cli` package and can be installed separately:
6969

7070
```sh
71-
npm install protobufjs-cli --save-dev
71+
npm install @tanglechat/protobufjs-cli --save-dev
7272
```
7373

7474
### Browsers
7575

7676
Pick the variant matching your needs and replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon. For example, to use the minified full variant:
7777

7878
```html
79-
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/protobuf.min.js"></script>
79+
<script src="//cdn.jsdelivr.net/npm/@tanglechat/[email protected]/dist/protobuf.min.js"></script>
8080
```
8181

8282
| Distribution | Location
8383
|--------------|--------------------------------------------------------
84-
| Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
85-
| Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
86-
| Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
84+
| Full | <https://cdn.jsdelivr.net/npm/@tanglechat/protobufjs/dist/>
85+
| Light | <https://cdn.jsdelivr.net/npm/@tanglechat/protobufjs/dist/light/>
86+
| Minimal | <https://cdn.jsdelivr.net/npm/@tanglechat/protobufjs/dist/minimal/>
8787

8888
All variants support CommonJS and AMD loaders and export globally as `window.protobuf`.
8989

cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Translates between file formats and generates static code.
6767
6868
--force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
6969
--force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
70+
--force-bigint Enforces the use of 'bigint' for s-/u-/int64 and s-/fixed64 fields.
7071
--force-message Enforces the use of message instances instead of plain objects.
7172
7273
--null-defaults Default value for optional fields is null instead of zero value.

cli/package-lock.json

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

cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "protobufjs-cli",
2+
"name": "@tanglechat/protobufjs-cli",
33
"description": "Translates between file formats and generates static code as well as TypeScript definitions.",
44
"version": "1.1.4",
55
"author": "Daniel Wirtz <[email protected]>",
@@ -18,7 +18,7 @@
1818
"pbts": "bin/pbts"
1919
},
2020
"peerDependencies": {
21-
"protobufjs": "^7.0.0"
21+
"@tanglechat/protobufjs": "^7.0.0"
2222
},
2323
"dependencies": {
2424
"chalk": "^4.0.0",

cli/pbjs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports.main = function main(args, callback) {
4141
"force-message": "strict-message"
4242
},
4343
string: [ "target", "out", "path", "wrap", "dependency", "root", "lint", "filter" ],
44-
boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "typeurl", "beautify", "comments", "service", "es6", "sparse", "keep-case", "alt-comment", "force-long", "force-number", "force-enum-string", "force-message", "null-defaults", "null-semantics"],
44+
boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "typeurl", "beautify", "comments", "service", "es6", "sparse", "keep-case", "alt-comment", "force-long", "force-number", "force-bigint", "force-enum-string", "force-message", "null-defaults", "null-semantics"],
4545
default: {
4646
target: "json",
4747
create: true,
@@ -60,6 +60,7 @@ exports.main = function main(args, callback) {
6060
"alt-comment": false,
6161
"force-long": false,
6262
"force-number": false,
63+
"force-bigint": false,
6364
"force-enum-string": false,
6465
"force-message": false,
6566
"null-defaults": false,
@@ -146,6 +147,7 @@ exports.main = function main(args, callback) {
146147
"",
147148
" --force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.",
148149
" --force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.",
150+
" --force-bigint Enforces the use of 'bigint' for s-/u-/int64 and s-/fixed64 fields.",
149151
" --force-message Enforces the use of message instances instead of plain objects.",
150152
"",
151153
" --null-defaults Default value for optional fields is null instead of zero value.",

cli/targets/static-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function static_module_target(root, options, callback) {
1818
return;
1919
}
2020
try {
21-
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/minimal" }, options));
21+
output = util.wrap(output, protobuf.util.merge({ dependency: "@tanglechat/protobufjs/minimal" }, options));
2222
} catch (e) {
2323
callback(e);
2424
return;

cli/targets/static.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function toJsType(field, parentIsInterface = false) {
335335
case "sint64":
336336
case "fixed64":
337337
case "sfixed64":
338-
type = config.forceLong ? "Long" : config.forceNumber ? "number" : "number|Long";
338+
type = config.forceBigint ? "bigint" : config.forceLong ? "Long" : config.forceNumber ? "number" : "number|Long|bigint";
339339
break;
340340
case "bool":
341341
type = "boolean";

src/converter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
6868
case "sint64":
6969
case "sfixed64": gen
7070
("if(typeof BigInt!==\"undefined\")")
71-
("m%s=(typeof d%s===\"number\"||typeof d%s===\"string\")?BigInt(d%s):util._toBigInt(d%s.low,d%s.high,%j)", prop, prop, prop, prop, prop, prop, isUnsigned)
71+
("m%s=typeof d%s===\"bigint\"?d%s:(typeof d%s===\"number\"||typeof d%s===\"string\")?BigInt(d%s):util._toBigInt(d%s.low,d%s.high,%j)", prop, prop, prop, prop, prop, prop, prop, prop, isUnsigned)
7272
("else if(util.Long)")
7373
("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned)
7474
("else if(typeof d%s===\"string\")", prop)
@@ -185,6 +185,8 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
185185
case "sfixed64": gen
186186
("if(typeof m%s===\"number\")", prop)
187187
("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
188+
("else if(typeof m%s===\"bigint\")", prop)
189+
("d%s=o.longs===String?m%s.toString():o.longs===Number?util.LongBits.fromBigInt(m%s).toNumber(%s):m%s", prop, prop, prop, isUnsigned ? "true": "", prop)
188190
("else") // Long-like
189191
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):o.longs===BigInt?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toBigInt(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop, prop, isUnsigned ? "true": "", prop);
190192
break;

0 commit comments

Comments
 (0)