Skip to content
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
merged 56 commits into from
May 24, 2019

Conversation

thephoenixofthevoid
Copy link
Contributor

@thephoenixofthevoid thephoenixofthevoid commented Apr 26, 2019

  1. Encoder refactoring
  2. Support encoding/decoding Maps instances [Fix integer keys / Map encoding #63 and This implementation does not strictly adhere to the spec #10 possibly]
  3. Support sorting objects keys when serialization [Fix Add an option to support predicable encoding #52]
  4. Fix encodeFloat implementation [Fix Too complicated encodeFloat function. #77]
  5. TimestampEncoding is treated as an ext-type with type === -1 (inaccessible from user API though)

thephoenixofthevoid and others added 30 commits April 23, 2019 00:55
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants