-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JavaScript): Support oneof (#1348)
### 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) ```
- Loading branch information
1 parent
cb49d11
commit 2f2e60f
Showing
17 changed files
with
467 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.