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

Refactoting of decoder for better maintainability #76

Merged
merged 40 commits into from Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a0f5f62
Feature: Manually encode unsuppoted object.
thephoenixofthevoid Apr 22, 2019
12f63ee
Refactoring: inlining hasMinBufferSize and simplifying decode(buf)
thephoenixofthevoid Apr 23, 2019
991cc76
Used while where it actually meant to.
thephoenixofthevoid Apr 23, 2019
287d374
In decodeMap(...) simplify counting amount of bytes consumed
thephoenixofthevoid Apr 23, 2019
f7345f0
Imporove maintainability
thephoenixofthevoid Apr 23, 2019
8a932aa
Getting rid of "offset + 1" artificial expression
thephoenixofthevoid Apr 23, 2019
a9ec4fb
Keep on getting intent more clear
thephoenixofthevoid Apr 23, 2019
11ef5e6
Implemented all integers and all kinds of floats
thephoenixofthevoid Apr 23, 2019
65ce0ba
Added missing Ranges as TODO commends
thephoenixofthevoid Apr 23, 2019
c5789c7
function decodeStr (buf, offset, size)
thephoenixofthevoid Apr 23, 2019
a511bdd
Added decodeBuffers
thephoenixofthevoid Apr 23, 2019
db3f3e8
gitignore updated
thephoenixofthevoid Apr 23, 2019
3ae90f9
if (inRange(0xc7, 0xc9)) return decodeExts(buf, offset, size - 2)
thephoenixofthevoid Apr 23, 2019
a902377
decodeFixExt + Moved functions outside of closure
thephoenixofthevoid Apr 23, 2019
e3546c8
It was just a line!
thephoenixofthevoid Apr 23, 2019
6319853
Update .gitignore
thephoenixofthevoid Apr 23, 2019
f2840b6
decodeArray
thephoenixofthevoid Apr 23, 2019
ebb90c0
small arrays and
thephoenixofthevoid Apr 23, 2019
67d253c
decodeMaps + ordering
thephoenixofthevoid Apr 23, 2019
83cb8ac
fixmap fixarr fixstr
thephoenixofthevoid Apr 23, 2019
e3be779
Inline buf.readUIntBE(offset, size) method where getLength (buf, offs…
thephoenixofthevoid Apr 24, 2019
f70ee03
function decodeTimestamp (buf, size, headerSize) moved to helper
thephoenixofthevoid Apr 24, 2019
c2c4b18
Use array syntax to handle results
thephoenixofthevoid Apr 24, 2019
6f725ac
Few changes
thephoenixofthevoid Apr 25, 2019
76a8958
Avoid using length var at top level
thephoenixofthevoid Apr 25, 2019
8d5003a
Avoid using result var at top level
thephoenixofthevoid Apr 25, 2019
672e68c
remove dist folder from git
thephoenixofthevoid Apr 25, 2019
698c73e
Restore dist files
thephoenixofthevoid Apr 25, 2019
c2e3c1b
Restore dist min files
thephoenixofthevoid Apr 25, 2019
2cbbaeb
Finally restore min version
thephoenixofthevoid Apr 25, 2019
4b7f55f
Inline decodeExts helper
thephoenixofthevoid Apr 25, 2019
c53969f
Revert transform unsupported
thephoenixofthevoid Apr 25, 2019
c80300c
Clean up index.js
thephoenixofthevoid Apr 25, 2019
c02177f
Import IncompleteBufferError from helpers.js and not reexport in deco…
thephoenixofthevoid Apr 25, 2019
1d96857
Remove passing transformUnsupported option from index.js
thephoenixofthevoid Apr 25, 2019
45a8340
Small fixes
thephoenixofthevoid Apr 25, 2019
b5bd1fd
Small fixes
thephoenixofthevoid Apr 25, 2019
40d2871
Fix travis builds
thephoenixofthevoid Apr 25, 2019
311de36
Fix travis builds 2
thephoenixofthevoid Apr 25, 2019
4a404e2
Fix travis builds 3
thephoenixofthevoid Apr 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -26,4 +26,4 @@ build/Release
node_modules
spec.html spec.md

package-lock.json
package-lock.json
25 changes: 11 additions & 14 deletions index.js
Expand Up @@ -6,36 +6,33 @@ var bl = require('bl')
var streams = require('./lib/streams')
var buildDecode = require('./lib/decoder')
var buildEncode = require('./lib/encoder')
var IncompleteBufferError = require('./lib/helpers.js').IncompleteBufferError

function msgpack (options) {
var encodingTypes = []
var decodingTypes = []
var decodingTypes = Object.create(null)

options = options || {
forceFloat64: false,
compatibilityMode: false,
disableTimestampEncoding: false // if true, skips encoding Dates using the msgpack timestamp ext format (-1)
// if true, skips encoding Dates using the msgpack
// timestamp ext format (-1)
disableTimestampEncoding: false
}

function registerEncoder (check, encode) {
assert(check, 'must have an encode function')
assert(encode, 'must have an encode function')

encodingTypes.push({
check: check, encode: encode
})
encodingTypes.push({ check, encode })

return this
}

function registerDecoder (type, decode) {
assert(type >= 0, 'must have a non-negative type')
assert(decode, 'must have a decode function')

decodingTypes.push({
type: type, decode: decode
})

decodingTypes[type] = decode
return this
}

Expand Down Expand Up @@ -70,15 +67,15 @@ function msgpack (options) {
return {
encode: buildEncode(encodingTypes, options.forceFloat64, options.compatibilityMode, options.disableTimestampEncoding),
decode: buildDecode(decodingTypes),
register: register,
registerEncoder: registerEncoder,
registerDecoder: registerDecoder,
register,
registerEncoder,
registerDecoder,
encoder: streams.encoder,
decoder: streams.decoder,
// needed for levelup support
buffer: true,
type: 'msgpack5',
IncompleteBufferError: buildDecode.IncompleteBufferError
IncompleteBufferError
}
}

Expand Down