Skip to content

Commit

Permalink
Fix assertion for FIXED32 scalar type when parsing JSON (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Apr 3, 2024
1 parent 2b2861b commit 3295dff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/protobuf-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ server would usually do.

| code generator | bundle size | minified | compressed |
|---------------------|------------------------:|-----------------------:|-------------------:|
| protobuf-es | 97,734 b | 41,763 b | 10,857 b |
| protobuf-es | 97,764 b | 41,777 b | 10,850 b |
| protobuf-javascript | 394,384 b | 288,654 b | 45,122 b |
4 changes: 2 additions & 2 deletions packages/protobuf/src/binary-encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export interface IBinaryReader {
skip(wireType: WireType): Uint8Array;

/**
* Read a `int32` field, a signed 32 bit varint.
* Read a `uint32` field, an unsigned 32 bit varint.
*/
uint32(): number;

/**
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
* Read a `int32` field, a signed 32 bit varint.
*/
int32(): number;

Expand Down
3 changes: 2 additions & 1 deletion packages/protobuf/src/private/json-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ function readScalar(
if (json.trim().length === json.length) int32 = Number(json);
}
if (int32 === undefined) break;
if (type == ScalarType.UINT32) assertUInt32(int32);
if (type == ScalarType.UINT32 || type == ScalarType.FIXED32)
assertUInt32(int32);
else assertInt32(int32);
return int32;

Expand Down

0 comments on commit 3295dff

Please sign in to comment.