-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Improve internals and add some features #78
Merged
mcollina
merged 56 commits into
mcollina:master
from
thephoenixofthevoid:improve-internals
May 24, 2019
Merged
Improve internals and add some features #78
mcollina
merged 56 commits into
mcollina:master
from
thephoenixofthevoid:improve-internals
May 24, 2019
Conversation
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
Contributor
thephoenixofthevoid
commented
Apr 26, 2019
•
edited
Loading
edited
- Encoder refactoring
- Support encoding/decoding Maps instances [Fix integer keys / Map encoding #63 and This implementation does not strictly adhere to the spec #10 possibly]
- Support sorting objects keys when serialization [Fix Add an option to support predicable encoding #52]
- Fix encodeFloat implementation [Fix Too complicated encodeFloat function. #77]
- TimestampEncoding is treated as an ext-type with type === -1 (inaccessible from user API though)
Changes to be committed: modified: lib/decoder.js
Well, provided that initialOffset is the value passed as an argument: console.log(headerLength + totalBytesConsumed === offset - initialOffset) // true --- always
1. getSize now is implemented through hash not switch statement. More concise and appear to be much faster. 2. Created helpers.js file, and functions that logically unrelated to decoding/encoding will go there. 3. Where possible prefer flat code that nested branches 4. In decodeExt dramatically simplify all the things. Changes to be committed: modified: lib/decoder.js new file: lib/helpers.js
It's caused by not incrementing offset after reaading first byte. To handle this change I first of all introduce "initialOffset" and change everywhere offset to "initial offset". This commit does this part of the job. Then I will clean 1-by-1 every affected function and branch.
1. Remove "else" statements that go after "return" 2. Where appropriate (another 1-4 bytes have been read) offset is incremented 3. So that expressions like "initialOffset + 2" --- "... + 5" could be replaced by just "offset" Changes to be committed: modified: lib/decoder.js
1. function decodeSigned (buf, offset, size) 2. function decodeFloat (buf, offset, size) 3. function decodeExt (buf, offset, type, size, headerSize)
Currently: | RANGE | STATUS | function name (if exists) or type name | |------------|---------------------|-----------------| | 0x00, 0x7f | MISSING COMPLETELY | positive fixint | 0x80, 0x8f | MISSING COMPLETELY | fixmap | 0x90, 0x9f | MISSING COMPLETELY | fixarr | 0xa0, 0xbf | MISSING COMPLETELY | fixstr | 0xc0, 0xc3 | DONE | decodeConstants(...) | 0xc4, 0xc6 | OLD CODE | decodeBuffers(...) | 0xc7, 0xc9 | WIP NOW | decodeExt(...) | 0xca, 0xcb | DONE | decodeFloat | 0xcc, 0xcf | DONE | decodeUnsignedInt() | 0xd0, 0xd3 | DONE | decodeSigned() | 0xd4, 0xd8 | DONE | decodeFixExt() | 0xd9, 0xdb | OLD CODE | decodeStr(...) | 0xdc, 0xdd | OLD CODE | decodeArray(...) | 0xde, 0xdf | OLD CODE | decodeMap(...) | 0xe0, 0xff | MISSING COMPLETELY | negative fixint
This was referenced Mar 12, 2021
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.