-
Notifications
You must be signed in to change notification settings - Fork 259
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
feat(JavaScript): Support oneof #1348
Conversation
I think here has a wrong behavior, the deserialize result should has a kind property also, which indicates that the kind of the raw obj |
The protocol natively supports polymorphism, making a 'kind' field to describe the object type unnecessary. |
ok, It still can meet my needs. |
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.
LGTM
### 1. Fixed a performance bug that caused writeInt32 to slow down Before: ```JavaScript // reader/index.ts function writeVarInt32() { buffer.byteLength } ``` After: ```JavaScript // reader/index.ts const byteLength = buffer.byteLength; function writeVarInt32() { byteLength } ``` The byteLength property in a Buffer is slow to access. It appears that when we access byteLength, the V8 engine processes it using a hash lookup. so we store it in closure. ### 2. Support Oneof Sometimes, the data we want to serialize does not have a confirmed type; instead, it could be one of several confirmed types. If we use an object to handle this situation, the size of the resulting binary will be too large, as it will contain much unused information. usage: ```JavaScript const oneOfThree = Type.oneof({ option1: Type.string(), option2: Type.object("foo", { a: Type.int32() }), option3: Type.int32(), }); const fury = new Fury({ refTracking: true }); const { serialize, deserialize } = fury.registerSerializer(oneOfThree); const obj = { option1: "hello" } const input = serialize(obj); const result = deserialize( input ); expect(result).toEqual(obj.option1) ```
1. Fixed a performance bug that caused writeInt32 to slow down
Before:
After:
The byteLength property in a Buffer is slow to access. It appears that when we access byteLength, the V8 engine processes it using a hash lookup. so we store it in closure.
2. Support Oneof
Sometimes, the data we want to serialize does not have a confirmed type; instead, it could be one of several confirmed types. If we use an object to handle this situation, the size of the resulting binary will be too large, as it will contain much unused information.
usage: