-
Notifications
You must be signed in to change notification settings - Fork 358
feat(xlang): add unsigned integer type support for JavaScript #3139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hey @chaokunyang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for unsigned integer types to the Fory JavaScript/TypeScript library, bringing it into parity with other language implementations (Rust, Go, C++, Python). The implementation adds 7 new unsigned integer types with corresponding serializers, type helpers, and comprehensive tests.
Changes:
- Added 7 unsigned integer types (uint8, uint16, uint32, var_uint32, uint64, var_uint64, tagged_uint64) to the InternalSerializerType enum
- Implemented Type helper functions and TypeScript type hints for proper type inference
- Registered serializers for all unsigned integer types using existing reader/writer methods
- Added comprehensive test coverage for all new types
- Normalized code formatting and indentation in typeInfo.ts
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| javascript/packages/fory/lib/type.ts | Added 7 unsigned integer type enum values to InternalSerializerType |
| javascript/packages/fory/lib/typeInfo.ts | Added Type helper functions (uint8-taggedUInt64), updated TypeScript type hints for number/bigint inference, and normalized code formatting |
| javascript/packages/fory/lib/gen/number.ts | Registered serializers for all 7 unsigned types using buildNumberSerializer pattern with appropriate reader/writer methods |
| javascript/test/number.test.ts | Added comprehensive tests for all 7 unsigned integer types testing serialization/deserialization with appropriate boundary values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@chaokunyang |
Great work! It's good to improve the readability. May be you can make some change for the check rules to avoid the CI failure |
Hey @theweipeng |
|
Here is our ci configuration: javascript:
name: JavaScript CI
strategy:
matrix:
node-version: [18, 20, 24]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache-dependency-path: javascript/package-lock.json
cache: "npm"
- name: Upgrade npm
run: npm install -g npm@8
# node-gyp needs to use python and relies on the distutils module.
# The distutils module has been removed starting from python 3.12
# (see https://docs.python.org/3.10/library/distutils.html). Some
# OS (such as macos-latest) uses python3.12 by default, so python 3.8
# is used here to avoid this problem.
- name: Set up Python3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Run CI with NodeJS
run: python ./ci/run_ci.py javascriptYou can run tests locally to see why it's failed, or you can look into the error message for how to fix it |
If you feel hard to chage the CI script, you can revert this part of code. I will change it next PR. |
Actually i want to learn this thing. I'll give it a look for a while, and if i'm unable to get things done, i'll revert the changes. |
Hey @chaokunyang |
Why?
As requested in Issue #3130, JavaScript implementation was missing support for unsigned integer types that are already available in other Fory language implementations (Rust, Go, C++, Python). This PR adds complete unsigned integer support for JavaScript.
What does this PR do?
This PR implements schema-based support for unsigned integer types in the Fory JavaScript/TypeScript library:
Added Types
uint8uint16uint32uint64var_uint32var_uint64tagged_uint64Changes Made
1.
lib/type.tsAdded 7 unsigned integer types to the
InternalSerializerTypeenum:2.
lib/typeInfo.tsAdded Type helper functions for user-facing API:
Updated TypeScript type hints for proper type inference:
numberfor 8/16/32-bit,bigintfor 64-bit)3.
lib/gen/number.tsRegistered serializers for all 7 unsigned integer types using the existing buildNumberSerializer pattern:
4.
test/number.test.tsAdded comprehensive tests for all unsigned types:
Usage Example
Related issues
Does this PR introduce any user-facing change?
Does this PR introduce any public API change?
Type.uint8(),Type.uint16(),Type.uint32(),Type.varUInt32(),Type.uint64(),Type.varUInt64(),Type.taggedUInt64())Does this PR introduce any binary protocol compatibility change?
Benchmark
N/A - this PR adds new functionality without modifying existing serialization paths. The underlying writer/reader methods
uint8(),uint16()were already implemented and optimized; this PR only exposes them through the type system.