Socket
Socket
Sign inDemoInstall

msgpack5

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msgpack5 - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

test/compatibility-mode.js

21

benchmarks/encodedecode.js

@@ -1,12 +0,11 @@

var msgpack = require('../')()
, msg = { hello: 'world' }
, encode = msgpack.encode
, decode = msgpack.decode
, max = 100000
, start
, stop
, i
var msg = { hello: 'world' }
var encode = msgpack.encode
var decode = msgpack.decode
var max = 100000
var start
var stop
var i
function run() {
function run () {
for (i = 0; i < max; i++) {

@@ -17,6 +16,6 @@ decode(encode(msg))

//preheat
// preheat
run()
start = Date.now()
start = Date.now()
run()

@@ -23,0 +22,0 @@ stop = Date.now()

@@ -1,12 +0,11 @@

var msgpack = require('../')()
, bl = require('bl')
, msg = bl(msgpack.encode({ hello: 'world' }))
, decode = msgpack.decode
, max = 1000000
, start
, stop
, i
var bl = require('bl')
var msg = bl(msgpack.encode({ hello: 'world' }))
var decode = msgpack.decode
var max = 1000000
var start
var stop
var i
function run() {
function run () {
for (i = 0; i < max; i++) {

@@ -17,6 +16,6 @@ decode(msg.duplicate())

//preheat
// preheat
run()
start = Date.now()
start = Date.now()
run()

@@ -23,0 +22,0 @@ stop = Date.now()

@@ -1,7 +0,5 @@

var msgpack = require('./')() // namespace our extensions
, a = new MyType(2, 'a')
, encode = msgpack.encode
, decode = msgpack.decode
var a = new MyType(2, 'a')
var encode = msgpack.encode
var decode = msgpack.decode

@@ -21,8 +19,8 @@ msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)

function MyType(size, value) {
function MyType (size, value) {
this.value = value
this.size = size
this.size = size
}
function mytipeEncode(obj) {
function mytipeEncode (obj) {
var buf = new Buffer(obj.size)

@@ -33,8 +31,8 @@ buf.fill(obj.value)

function mytipeDecode(data) {
function mytipeDecode (data) {
var result = new MyType(data.length, data.toString('utf8', 0, 1))
, i
var i
for (i = 0; i < data.length; i++) {
if (data.readUInt8(0) != data.readUInt8(i)) {
if (data.readUInt8(0) != data.readUInt8(i)) { // eslint-disable-line
throw new Error('should all be the same')

@@ -41,0 +39,0 @@ }

@@ -0,16 +1,17 @@

var assert = require('assert')
var bl = require('bl')
var streams = require('./lib/streams')
var buildDecode = require('./lib/decoder')
var buildEncode = require('./lib/encoder')
var assert = require('assert')
, bl = require('bl')
, streams = require('./lib/streams')
, buildDecode = require('./lib/decoder')
, buildEncode = require('./lib/encoder')
function msgpack(options) {
function msgpack (options) {
var encodingTypes = []
, decodingTypes = []
var decodingTypes = []
options = options ? options : { forceFloat64: false }
options = options || {
forceFloat64: false,
compatibilityMode: false
}
function registerEncoder(check, encode) {
function registerEncoder (check, encode) {
assert(check, 'must have an encode function')

@@ -20,4 +21,3 @@ assert(encode, 'must have an encode function')

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

@@ -28,3 +28,3 @@

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

@@ -34,4 +34,3 @@ assert(decode, 'must have a decode function')

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

@@ -42,3 +41,3 @@

function register(type, constructor, encode, decode) {
function register (type, constructor, encode, decode) {
assert(constructor, 'must have a constructor')

@@ -49,9 +48,9 @@ assert(encode, 'must have an encode function')

function check(obj) {
function check (obj) {
return (obj instanceof constructor)
}
function reEncode(obj) {
function reEncode (obj) {
var buf = bl()
, header = new Buffer(1)
var header = new Buffer(1)

@@ -73,14 +72,13 @@ header.writeInt8(type, 0)

return {
encode: buildEncode(encodingTypes, options.forceFloat64)
, decode: buildDecode(decodingTypes)
, register: register
, registerEncoder: registerEncoder
, registerDecoder: registerDecoder
, encoder: streams.encoder
, decoder: streams.decoder
encode: buildEncode(encodingTypes, options.forceFloat64, options.compatibilityMode),
decode: buildDecode(decodingTypes),
register: register,
registerEncoder: registerEncoder,
registerDecoder: registerDecoder,
encoder: streams.encoder,
decoder: streams.decoder,
// needed for levelup support
, buffer: true
, type: 'msgpack5'
, IncompleteBufferError: buildDecode.IncompleteBufferError
buffer: true,
type: 'msgpack5',
IncompleteBufferError: buildDecode.IncompleteBufferError
}

@@ -87,0 +85,0 @@ }

@@ -1,11 +0,11 @@

var bl = require('bl')
, util = require('util')
var bl = require('bl')
var util = require('util')
function IncompleteBufferError(message) {
Error.call(this); //super constructor
function IncompleteBufferError (message) {
Error.call(this) // super constructor
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor); //super helper method to include stack trace in error object
Error.captureStackTrace(this, this.constructor) // super helper method to include stack trace in error object
}
this.name = this.constructor.name
this.message = message || "unable to decode"
this.message = message || 'unable to decode'
}

@@ -15,8 +15,6 @@

module.exports = function buildDecode (decodingTypes) {
return decode
module.exports = function buildDecode(decodingTypes) {
return decode;
function getSize(first) {
function getSize (first) {
switch (first) {

@@ -78,3 +76,3 @@ case 0xc4:

function hasMinBufferSize(first, length) {
function hasMinBufferSize (first, length) {
var size = getSize(first)

@@ -89,7 +87,7 @@

function isValidDataSize(dataLength, bufLength, headerLength) {
function isValidDataSize (dataLength, bufLength, headerLength) {
return bufLength >= headerLength + dataLength
}
function buildDecodeResult(value, bytesConsumed) {
function buildDecodeResult (value, bytesConsumed) {
return {

@@ -101,3 +99,3 @@ value: value,

function decode(buf) {
function decode (buf) {
if (!(buf instanceof bl)) {

@@ -116,3 +114,3 @@ buf = bl().append(buf)

function tryDecode(buf, offset) {
function tryDecode (buf, offset) {
offset = offset === undefined ? 0 : offset

@@ -125,6 +123,6 @@ var bufLength = buf.length - offset

var first = buf.readUInt8(offset)
, length
, result = 0
, type
, bytePos
var length
var result = 0
var type
var bytePos

@@ -158,3 +156,3 @@ if (!hasMinBufferSize(first, bufLength)) {

for (bytePos = 7; bytePos >= 0; bytePos--) {
result += (buf.readUInt8(offset + bytePos + 1) * Math.pow(2 , (8 *(7-bytePos))));
result += (buf.readUInt8(offset + bytePos + 1) * Math.pow(2, (8 * (7 - bytePos))))
}

@@ -308,3 +306,3 @@ return buildDecodeResult(result, 9)

}
} else if (first >= 0xe0) {
} else if (first >= 0xe0) {
// 5 bits negative ints

@@ -321,11 +319,11 @@ result = first - 0x100

function readInt64BE(buf, offset) {
var negate = (buf[offset] & 0x80) == 0x80
function readInt64BE (buf, offset) {
var negate = (buf[offset] & 0x80) == 0x80 // eslint-disable-line
if (negate) {
var carry = 1;
var carry = 1
for (var i = offset + 7; i >= offset; i--) {
var v = (buf[i] ^ 0xff) + carry;
buf[i] = v & 0xff;
carry = v >> 8;
var v = (buf[i] ^ 0xff) + carry
buf[i] = v & 0xff
carry = v >> 8
}

@@ -335,10 +333,10 @@ }

var hi = buf.readUInt32BE(offset + 0)
, lo = buf.readUInt32BE(offset + 4)
var lo = buf.readUInt32BE(offset + 4)
return (hi * 4294967296 + lo) * (negate ? -1 : +1)
}
function decodeArray(buf, offset, length, headerLength) {
function decodeArray (buf, offset, length, headerLength) {
var result = []
, i
, totalBytesConsumed = 0
var i
var totalBytesConsumed = 0

@@ -359,7 +357,7 @@ offset += headerLength

function decodeMap(buf, offset, length, headerLength) {
function decodeMap (buf, offset, length, headerLength) {
var result = {}
, key
, i
, totalBytesConsumed = 0
var key
var i
var totalBytesConsumed = 0

@@ -387,3 +385,3 @@ offset += headerLength

function decodeFixExt(buf, offset, size) {
function decodeFixExt (buf, offset, size) {
var type = buf.readUInt8(offset + 1)

@@ -394,5 +392,5 @@

function decodeExt(buf, offset, type, size, headerSize) {
var i
, toDecode
function decodeExt (buf, offset, type, size, headerSize) {
var i,
toDecode

@@ -399,0 +397,0 @@ offset += headerSize

@@ -0,10 +1,9 @@

var bl = require('bl')
var TOLERANCE = 0.1
var bl = require('bl')
, TOLERANCE = 0.1
module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilityMode) {
function encode (obj, avoidSlice) {
var buf,
len
module.exports = function buildEncode(encodingTypes, forceFloat64) {
function encode(obj, avoidSlice) {
var buf
, len
if (obj === undefined) {

@@ -27,3 +26,4 @@ throw new Error('undefined is not encodable in msgpack!')

buf.write(obj, 1)
} else if (len <= 0xff) {
} else if (len <= 0xff && !compatibilityMode) {
// str8, but only when not in compatibility mode
buf = new Buffer(2 + len)

@@ -76,3 +76,3 @@ buf[0] = 0xd9

buf = obj.reduce(function(acc, obj) {
buf = obj.reduce(function (acc, obj) {
acc.append(encode(obj, true))

@@ -110,3 +110,3 @@ return acc

} else {
if (obj >= -32) {
if (obj >= -32) {
buf = new Buffer(1)

@@ -136,16 +136,18 @@ buf[0] = 0x100 + obj

if (!buf)
if (!buf) {
throw new Error('not implemented yet')
}
if (avoidSlice)
if (avoidSlice) {
return buf
else
} else {
return buf.slice()
}
}
function encodeExt(obj) {
function encodeExt (obj) {
var i
, encoded
, length = -1
, headers = []
var encoded
var length = -1
var headers = []

@@ -155,3 +157,3 @@ for (i = 0; i < encodingTypes.length; i++) {

encoded = encodingTypes[i].encode(obj)
break;
break
}

@@ -196,12 +198,12 @@ }

function encodeObject(obj) {
function encodeObject (obj) {
var acc = []
, length = 0
, key
, header
var length = 0
var key
var header
for (key in obj) {
if (obj.hasOwnProperty(key) &&
obj[key] !== undefined &&
"function" !== typeof obj[key] ) {
obj[key] !== undefined &&
typeof obj[key] !== 'function') {
++length

@@ -224,3 +226,3 @@ acc.push(encode(key, true))

var result = acc.reduce(function(list, buf) {
var result = acc.reduce(function (list, buf) {
return list.append(buf)

@@ -235,18 +237,19 @@ }, bl())

function write64BitUint(buf, obj) {
// Write long byte by byte, in big-endian order
function write64BitUint (buf, obj) {
// Write long byte by byte, in big-endian order
for (var currByte = 7; currByte >= 0; currByte--) {
buf[currByte + 1] = (obj & 0xff);
obj = obj / 256;
buf[currByte + 1] = (obj & 0xff)
obj = obj / 256
}
}
function write64BitInt(buf, offset, num) {
function write64BitInt (buf, offset, num) {
var negate = num < 0
if (negate)
if (negate) {
num = Math.abs(num)
}
var lo = num % 4294967296
, hi = num / 4294967296
var hi = num / 4294967296
buf.writeUInt32BE(Math.floor(hi), offset + 0)

@@ -256,7 +259,7 @@ buf.writeUInt32BE(lo, offset + 4)

if (negate) {
var carry = 1;
var carry = 1
for (var i = offset + 7; i >= offset; i--) {
var v = (buf[i] ^ 0xff) + carry;
buf[i] = v & 0xff;
carry = v >> 8;
var v = (buf[i] ^ 0xff) + carry
buf[i] = v & 0xff
carry = v >> 8
}

@@ -266,7 +269,7 @@ }

function isFloat(n) {
function isFloat (n) {
return n !== Math.floor(n)
}
function encodeFloat(obj, forceFloat64) {
function encodeFloat (obj, forceFloat64) {
var buf

@@ -273,0 +276,0 @@

@@ -1,7 +0,6 @@

var Transform = require('readable-stream').Transform
, inherits = require('inherits')
, bl = require('bl')
var inherits = require('inherits')
var bl = require('bl')
function Base(opts) {
function Base (opts) {
opts = opts || {}

@@ -19,3 +18,3 @@

function Encoder(opts) {
function Encoder (opts) {
if (!(this instanceof Encoder)) {

@@ -32,3 +31,3 @@ opts = opts || {}

Encoder.prototype._transform = function(obj, enc, done) {
Encoder.prototype._transform = function (obj, enc, done) {
var buf = null

@@ -38,3 +37,3 @@

buf = this._msgpack.encode(obj).slice(0)
} catch(err) {
} catch (err) {
this.emit('error', err)

@@ -48,3 +47,3 @@ return done()

function Decoder(opts) {
function Decoder (opts) {
if (!(this instanceof Decoder)) {

@@ -71,3 +70,3 @@ opts = opts || {}

this.push(result)
} catch(err) {
} catch (err) {
if (err instanceof this._msgpack.IncompleteBufferError) {

@@ -74,0 +73,0 @@ done()

{
"name": "msgpack5",
"version": "3.3.0",
"version": "3.4.0",
"description": "A msgpack v5 implementation for node.js and the browser, with extension points",
"main": "index.js",
"scripts": {
"test": "tape test/* | faucet",
"jshint": "jshint *.js test/*",
"test": "standard && tape test/* | faucet",
"build": "npm run browserify && npm run dist",

@@ -15,3 +14,2 @@ "browserify": "node_modules/.bin/browserify index.js -o dist/msgpack5.js -s msgpack5",

"pre-commit": [
"jshint",
"test"

@@ -43,2 +41,3 @@ ],

"pre-commit": "1.0.10",
"standard": "^6.0.4",
"tape": "^4.0.0",

@@ -48,2 +47,7 @@ "testling": "^1.7.1",

},
"standard": {
"ignore": [
"dist/"
]
},
"testling": {

@@ -50,0 +54,0 @@ "files": "test/*.js",

@@ -107,3 +107,4 @@ msgpack5&nbsp;&nbsp;[![Build Status](https://travis-ci.org/mcollina/msgpack5.png)](https://travis-ci.org/mcollina/msgpack5)

- `forceFloat64`, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults is false.
- `forceFloat64`, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults to false.
- `compatibilityMode`, a boolean that enables "compatibility mode" which doesn't use str 8 format. Defaults to false.

@@ -110,0 +111,0 @@ -------------------------------------------------------

@@ -0,7 +1,8 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var buf

@@ -15,6 +16,5 @@

test('encode/decode 2^8-1 bytes buffers', function(t) {
test('encode/decode 2^8-1 bytes buffers', function (t) {
var encoder = msgpack()
, all = []
var all = []

@@ -26,13 +26,13 @@ all.push(build(Math.pow(2, 8) - 1))

all.forEach(function(orig) {
t.test('encoding a buffer of length ' + orig.length, function(t) {
all.forEach(function (orig) {
t.test('encoding a buffer of length ' + orig.length, function (t) {
var buf = encoder.encode(orig)
t.equal(buf.length, 2 + orig.length, 'must have the right length');
t.equal(buf.readUInt8(0), 0xc4, 'must have the proper header');
t.equal(buf.readUInt8(1), orig.length, 'must include the buf length');
t.equal(buf.toString('utf8', 2), orig.toString('utf8'), 'must decode correctly');
t.equal(buf.length, 2 + orig.length, 'must have the right length')
t.equal(buf.readUInt8(0), 0xc4, 'must have the proper header')
t.equal(buf.readUInt8(1), orig.length, 'must include the buf length')
t.equal(buf.toString('utf8', 2), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('decoding a buffer of length ' + orig.length, function(t) {
t.test('decoding a buffer of length ' + orig.length, function (t) {
var buf = new Buffer(2 + orig.length)

@@ -42,8 +42,8 @@ buf[0] = 0xc4

orig.copy(buf, 2)
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly');
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('mirror test a buffer of length ' + orig.length, function(t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same');
t.test('mirror test a buffer of length ' + orig.length, function (t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same')
t.end()

@@ -56,17 +56,19 @@ })

test('decoding a chopped 2^8-1 bytes buffer', function(t) {
test('decoding a chopped 2^8-1 bytes buffer', function (t) {
var encoder = msgpack()
var orig = build(Math.pow(2,6))
var orig = build(Math.pow(2, 6))
var buf = new Buffer(2 + orig.length)
buf[0] = 0xc4
buf[1] = Math.pow(2,8) - 1 // set bigger size
buf[1] = Math.pow(2, 8) - 1 // set bigger size
orig.copy(buf, 2)
buf = bl().append(buf)
var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of 2^8-1 bytes buffer', function(t) {
test('decoding an incomplete header of 2^8-1 bytes buffer', function (t) {
var encoder = msgpack()

@@ -77,5 +79,7 @@ var buf = new Buffer(1)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,17 +1,17 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode variable ext data up to 0xff', function(t) {
test('encode/decode variable ext data up to 0xff', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(size, value) {
function MyType (size, value) {
this.value = value
this.size = size
this.size = size
}
function mytipeEncode(obj) {
function mytipeEncode (obj) {
var buf = new Buffer(obj.size)

@@ -22,8 +22,7 @@ buf.fill(obj.value)

function mytipeDecode(data) {
function mytipeDecode (data) {
var result = new MyType(data.length, data.toString('utf8', 0, 1))
, i
for (i = 0; i < data.length; i++) {
if (data.readUInt8(0) != data.readUInt8(i)) {
for (var i = 0; i < data.length; i++) {
if (data.readUInt8(0) !== data.readUInt8(i)) {
throw new Error('should all be the same')

@@ -58,4 +57,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj of length ' + orig.size, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj of length ' + orig.size, function (t) {
var buf = encoder.encode(orig)

@@ -70,3 +69,3 @@ t.equal(buf.length, 3 + orig.size, 'must have the right length')

t.test('mirror test with a custom obj of length ' + orig.size, function(t) {
t.test('mirror test with a custom obj of length ' + orig.size, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -77,3 +76,3 @@ t.end()

t.test('decoding an incomplete variable ext data up to 0xff', function(t) {
t.test('decoding an incomplete variable ext data up to 0xff', function (t) {
var obj = encoder.encode(new MyType(250, 'a'))

@@ -86,8 +85,10 @@ var buf = new Buffer(obj.length)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete header of variable ext data up to 0xff', function(t) {
t.test('decoding an incomplete header of variable ext data up to 0xff', function (t) {
var buf = new Buffer(2)

@@ -97,4 +98,6 @@ buf[0] = 0xc7

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()

@@ -101,0 +104,0 @@ })

@@ -0,11 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode 32 <-> (2^8-1) bytes strings', function(t) {
test('encode/decode 32 <-> (2^8-1) bytes strings', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
var i

@@ -16,17 +16,17 @@ // build base

for (; i.length < Math.pow(2,8); i += 'aaaaa') {
for (; i.length < Math.pow(2, 8); i += 'aaaaa') {
all.push(i)
}
all.forEach(function(str) {
t.test('encoding a string of length ' + str.length, function(t) {
all.forEach(function (str) {
t.test('encoding a string of length ' + str.length, function (t) {
var buf = encoder.encode(str)
t.equal(buf.length, 2 + Buffer.byteLength(str), 'must be the proper length')
t.equal(buf.readUInt8(0), 0xd9, 'must have the proper header');
t.equal(buf.readUInt8(1), Buffer.byteLength(str), 'must include the str length');
t.equal(buf.toString('utf8', 2, Buffer.byteLength(str) + 2), str, 'must decode correctly');
t.equal(buf.readUInt8(0), 0xd9, 'must have the proper header')
t.equal(buf.readUInt8(1), Buffer.byteLength(str), 'must include the str length')
t.equal(buf.toString('utf8', 2, Buffer.byteLength(str) + 2), str, 'must decode correctly')
t.end()
})
t.test('decoding a string of length ' + str.length, function(t) {
t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(2 + Buffer.byteLength(str))

@@ -36,8 +36,8 @@ buf[0] = 0xd9

buf.write(str, 2)
t.equal(encoder.decode(buf), str, 'must decode correctly');
t.equal(encoder.decode(buf), str, 'must decode correctly')
t.end()
})
t.test('mirror test a string of length ' + str.length, function(t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same');
t.test('mirror test a string of length ' + str.length, function (t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same')
t.end()

@@ -50,5 +50,5 @@ })

test('decoding a chopped string', function(t) {
test('decoding a chopped string', function (t) {
var encoder = msgpack()
var str;
var str
for (str = 'a'; str.length < 40; str += 'a') {

@@ -62,8 +62,10 @@ }

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of a string', function(t) {
test('decoding an incomplete header of a string', function (t) {
var encoder = msgpack()

@@ -74,5 +76,7 @@ var buf = new Buffer(1)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,11 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size, obj) {
function build (size, obj) {
var array = []
, i
var i
for(i = 0; i < size; i++) {
for (i = 0; i < size; i++) {
array.push(obj)

@@ -17,5 +18,5 @@ }

function computeLength(array) {
function computeLength (array) {
var length = 1 // the header
, multi = 1
var multi = 1

@@ -31,29 +32,27 @@ if (array[0] && typeof array[0] === 'string') {

test('encode/decode arrays up to 15 elements', function(t) {
test('encode/decode arrays up to 15 elements', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
var i
for(i = 0; i < 16; i++) {
for (i = 0; i < 16; i++) {
all.push(build(i, 42))
}
for(i = 0; i < 16; i++) {
for (i = 0; i < 16; i++) {
all.push(build(i, 'aaa'))
}
all.forEach(function(array) {
t.test('encoding an array with ' + array.length + ' elements of ' + array[0], function(t) {
all.forEach(function (array) {
t.test('encoding an array with ' + array.length + ' elements of ' + array[0], function (t) {
var buf = encoder.encode(array)
// the array is full of 1-byte integers
t.equal(buf.length, computeLength(array), 'must have the right length');
t.equal(buf.readUInt8(0) & 0xf0, 0x90, 'must have the proper header');
t.equal(buf.readUInt8(0) & 0x0f, array.length, 'must include the array length');
t.equal(buf.length, computeLength(array), 'must have the right length')
t.equal(buf.readUInt8(0) & 0xf0, 0x90, 'must have the proper header')
t.equal(buf.readUInt8(0) & 0x0f, array.length, 'must include the array length')
t.end()
})
t.test('mirror test for an array of length ' + array.length + ' with ' + array[0], function(t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same');
t.test('mirror test for an array of length ' + array.length + ' with ' + array[0], function (t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same')
t.end()

@@ -64,6 +63,5 @@ })

t.end()
})
test('decoding an incomplete array', function(t) {
test('decoding an incomplete array', function (t) {
var encoder = msgpack()

@@ -83,5 +81,7 @@

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(origLength, buf.length, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(origLength, buf.length, 'must not consume any byte')
t.end()
})

@@ -0,11 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size, value) {
function build (size, value) {
var map = {}
, i
var i
for(i = 0; i < size; i++) {
for (i = 0; i < size; i++) {
map[i + 100 + ''] = value

@@ -17,5 +18,5 @@ }

function computeLength(map) {
var length = 1 // the header
, multi = 5 // we have 4 bytes for each key, plus 1 byte for the value
function computeLength (map) {
var length = 1 // the header
var multi = 5 // we have 4 bytes for each key, plus 1 byte for the value

@@ -31,29 +32,27 @@ if (map[100] && typeof map[100] === 'string') {

test('encode/decode maps up to 15 elements', function(t) {
test('encode/decode maps up to 15 elements', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
var i
for(i = 0; i < 16; i++) {
for (i = 0; i < 16; i++) {
all.push(build(i, 42))
}
for(i = 0; i < 16; i++) {
for (i = 0; i < 16; i++) {
all.push(build(i, 'aaa'))
}
all.forEach(function(map) {
all.forEach(function (map) {
var length = Object.keys(map).length
t.test('encoding a map with ' + length + ' elements of ' + map[100], function(t) {
t.test('encoding a map with ' + length + ' elements of ' + map[100], function (t) {
var buf = encoder.encode(map)
t.equal(buf.length, computeLength(map), 'must have the right length');
t.equal(buf.readUInt8(0) & 0xf0, 0x80, 'must have the proper header');
t.equal(buf.readUInt8(0) & 0x0f, length, 'must include the map length');
t.equal(buf.length, computeLength(map), 'must have the right length')
t.equal(buf.readUInt8(0) & 0xf0, 0x80, 'must have the proper header')
t.equal(buf.readUInt8(0) & 0x0f, length, 'must include the map length')
t.end()
})
t.test('mirror test for a map of length ' + length + ' with ' + map[100], function(t) {
t.deepEqual(encoder.decode(encoder.encode(map)), map, 'must stay the same');
t.test('mirror test for a map of length ' + length + ' with ' + map[100], function (t) {
t.deepEqual(encoder.decode(encoder.encode(map)), map, 'must stay the same')
t.end()

@@ -64,10 +63,9 @@ })

t.end()
})
test('do not encode undefined in a map', function(t) {
test('do not encode undefined in a map', function (t) {
var instance = msgpack()
, expected = { hello: 'world' }
, toEncode = { a: undefined, hello: 'world' }
, buf = instance.encode(toEncode)
var expected = { hello: 'world' }
var toEncode = { a: undefined, hello: 'world' }
var buf = instance.encode(toEncode)

@@ -78,11 +76,11 @@ t.deepEqual(expected, instance.decode(buf), 'must ignore undefined')

test('encode/decode map with buf, ints and strings', function(t) {
test('encode/decode map with buf, ints and strings', function (t) {
var map = {
topic: 'hello'
, qos: 1
, payload: new Buffer("world")
, messageId: '42'
, ttl: 1416309270167
}
, pack = msgpack()
topic: 'hello',
qos: 1,
payload: new Buffer('world'),
messageId: '42',
ttl: 1416309270167
}
var pack = msgpack()

@@ -93,5 +91,5 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

test('decoding a chopped map', function(t) {
test('decoding a chopped map', function (t) {
var encoder = msgpack()
var map = encoder.encode({"a": "b", "c": "d", "e": "f"})
var map = encoder.encode({'a': 'b', 'c': 'd', 'e': 'f'})
var buf = new Buffer(map.length)

@@ -102,5 +100,7 @@ buf[0] = 0x80 | 5 // set bigger size

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,10 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 16-bits big-endian signed integers', function(t) {
test('encoding/decoding 16-bits big-endian signed integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
var i

@@ -17,21 +18,21 @@ for (i = 129; i < 32768; i += 1423) {

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 3, 'must have 3 bytes')
t.equal(buf[0], 0xd1, 'must have the proper header');
t.equal(buf.readInt16BE(1), num, 'must decode correctly');
t.equal(buf[0], 0xd1, 'must have the proper header')
t.equal(buf.readInt16BE(1), num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(3)
buf[0] = 0xd1
buf.writeInt16BE(num, 1)
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -44,3 +45,3 @@ })

test('decoding an incomplete 16-bits big-endian integer', function(t) {
test('decoding an incomplete 16-bits big-endian integer', function (t) {
var encoder = msgpack()

@@ -51,5 +52,7 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,10 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 16-bits big-endian unsigned integers', function(t) {
test('encoding/decoding 16-bits big-endian unsigned integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
var i

@@ -17,21 +18,21 @@ for (i = 256; i < 65536; i += 1423) {

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 3, 'must have 3 bytes')
t.equal(buf[0], 0xcd, 'must have the proper header');
t.equal(buf.readUInt16BE(1), num, 'must decode correctly');
t.equal(buf[0], 0xcd, 'must have the proper header')
t.equal(buf.readUInt16BE(1), num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(3)
buf[0] = 0xcd
buf.writeUInt16BE(num, 1)
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -44,3 +45,3 @@ })

test('decoding an incomplete 16-bits big-endian unsigned integer', function(t) {
test('decoding an incomplete 16-bits big-endian unsigned integer', function (t) {
var encoder = msgpack()

@@ -51,5 +52,7 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,11 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var array = []
, i
var i
for(i = 0; i < size; i++) {
for (i = 0; i < size; i++) {
array.push(42)

@@ -17,9 +18,8 @@ }

test('encode/decode arrays up to 0xffff elements', function(t) {
test('encode/decode arrays up to 0xffff elements', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
var i
for(i = 16; i < 0xffff; i += 4242) {
for (i = 16; i < 0xffff; i += 4242) {
all.push(build(i))

@@ -31,14 +31,14 @@ }

all.forEach(function(array) {
t.test('encoding an array with ' + array.length + ' elements', function(t) {
all.forEach(function (array) {
t.test('encoding an array with ' + array.length + ' elements', function (t) {
var buf = encoder.encode(array)
// the array is full of 1-byte integers
t.equal(buf.length, 3 + array.length, 'must have the right length');
t.equal(buf.readUInt8(0), 0xdc, 'must have the proper header');
t.equal(buf.readUInt16BE(1), array.length, 'must include the array length');
t.equal(buf.length, 3 + array.length, 'must have the right length')
t.equal(buf.readUInt8(0), 0xdc, 'must have the proper header')
t.equal(buf.readUInt16BE(1), array.length, 'must include the array length')
t.end()
})
t.test('mirror test for an array of length ' + array.length, function(t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same');
t.test('mirror test for an array of length ' + array.length, function (t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same')
t.end()

@@ -49,9 +49,8 @@ })

t.end()
})
test('decoding an incomplete array', function(t) {
test('decoding an incomplete array', function (t) {
var encoder = msgpack()
var array = build(0xffff/2)
var array = build(0xffff / 2)
var buf = new Buffer(3 + array.length)

@@ -68,8 +67,10 @@ buf[0] = 0xdc

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(origLength, buf.length, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(origLength, buf.length, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header', function(t) {
test('decoding an incomplete header', function (t) {
var encoder = msgpack()

@@ -81,5 +82,7 @@

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,7 +1,8 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var buf

@@ -15,6 +16,5 @@

test('encode/decode 2^16-1 bytes buffers', function(t) {
test('encode/decode 2^16-1 bytes buffers', function (t) {
var encoder = msgpack()
, all = []
var all = []

@@ -26,13 +26,13 @@ all.push(build(Math.pow(2, 8)))

all.forEach(function(orig) {
t.test('encoding a buffer of length ' + orig.length, function(t) {
all.forEach(function (orig) {
t.test('encoding a buffer of length ' + orig.length, function (t) {
var buf = encoder.encode(orig)
t.equal(buf.length, 3 + orig.length, 'must have the right length');
t.equal(buf.readUInt8(0), 0xc5, 'must have the proper header');
t.equal(buf.readUInt16BE(1), orig.length, 'must include the buf length');
t.equal(buf.toString('utf8', 3), orig.toString('utf8'), 'must decode correctly');
t.equal(buf.length, 3 + orig.length, 'must have the right length')
t.equal(buf.readUInt8(0), 0xc5, 'must have the proper header')
t.equal(buf.readUInt16BE(1), orig.length, 'must include the buf length')
t.equal(buf.toString('utf8', 3), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('decoding a buffer of length ' + orig.length, function(t) {
t.test('decoding a buffer of length ' + orig.length, function (t) {
var buf = new Buffer(3 + orig.length)

@@ -42,8 +42,8 @@ buf[0] = 0xc5

orig.copy(buf, 3)
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly');
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('mirror test a buffer of length ' + orig.length, function(t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same');
t.test('mirror test a buffer of length ' + orig.length, function (t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same')
t.end()

@@ -56,17 +56,19 @@ })

test('decoding a chopped 2^16-1 bytes buffer', function(t) {
test('decoding a chopped 2^16-1 bytes buffer', function (t) {
var encoder = msgpack()
var orig = build(Math.pow(2,12))
var orig = build(Math.pow(2, 12))
var buf = new Buffer(3 + orig.length)
buf[0] = 0xc5
buf[1] = Math.pow(2,16) - 1 // set bigger size
buf[1] = Math.pow(2, 16) - 1 // set bigger size
orig.copy(buf, 3)
buf = bl().append(buf)
var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of 2^16-1 bytes buffer', function(t) {
test('decoding an incomplete header of 2^16-1 bytes buffer', function (t) {
var encoder = msgpack()

@@ -77,5 +79,7 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,17 +1,17 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode variable ext data up between 0x0100 and 0xffff', function(t) {
test('encode/decode variable ext data up between 0x0100 and 0xffff', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(size, value) {
function MyType (size, value) {
this.value = value
this.size = size
this.size = size
}
function mytipeEncode(obj) {
function mytipeEncode (obj) {
var buf = new Buffer(obj.size)

@@ -22,8 +22,7 @@ buf.fill(obj.value)

function mytipeDecode(data) {
function mytipeDecode (data) {
var result = new MyType(data.length, data.toString('utf8', 0, 1))
, i
for (i = 0; i < data.length; i++) {
if (data.readUInt8(0) != data.readUInt8(i)) {
for (var i = 0; i < data.length; i++) {
if (data.readUInt8(0) !== data.readUInt8(i)) {
throw new Error('should all be the same')

@@ -42,4 +41,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj of length ' + orig.size, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj of length ' + orig.size, function (t) {
var buf = encoder.encode(orig)

@@ -54,3 +53,3 @@ t.equal(buf.length, 4 + orig.size, 'must have the right length')

t.test('mirror test with a custom obj of length ' + orig.size, function(t) {
t.test('mirror test with a custom obj of length ' + orig.size, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -61,3 +60,3 @@ t.end()

t.test('decoding an incomplete variable ext data up between 0x0100 and 0xffff', function(t) {
t.test('decoding an incomplete variable ext data up between 0x0100 and 0xffff', function (t) {
var obj = encoder.encode(new MyType(0xfff0, 'a'))

@@ -70,8 +69,10 @@ var buf = new Buffer(obj.length)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete header of variable ext data up between 0x0100 and 0xffff', function(t) {
t.test('decoding an incomplete header of variable ext data up between 0x0100 and 0xffff', function (t) {
var buf = new Buffer(3)

@@ -81,4 +82,6 @@ buf[0] = 0xc8

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()

@@ -85,0 +88,0 @@ })

@@ -0,12 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
, base = 100000
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
var base = 100000
function build(size, value) {
function build (size, value) {
var map = {}
, i
for(i = 0; i < size; i++) {
for (var i = 0; i < size; i++) {
map[i + base] = value

@@ -18,5 +18,5 @@ }

function computeLength(mapLength) {
var length = 3 // the header
, multi = ('' + base).length + 1 + 1 // we have <base + 1> bytes for each key, plus 1 byte for the value
function computeLength (mapLength) {
var length = 3 // the header
var multi = ('' + base).length + 1 + 1 // we have <base + 1> bytes for each key, plus 1 byte for the value

@@ -28,20 +28,19 @@ length += mapLength * multi

test('encode/decode maps up to 2^16-1 elements', function(t) {
test('encode/decode maps up to 2^16-1 elements', function (t) {
var encoder = msgpack()
function doTest(length) {
function doTest (length) {
var map = build(length, 42)
, buf = encoder.encode(map)
var buf = encoder.encode(map)
t.test('encoding a map with ' + length + ' elements of ' + map[base], function(t) {
t.test('encoding a map with ' + length + ' elements of ' + map[base], function (t) {
// the map is full of 1-byte integers
t.equal(buf.length, computeLength(length), 'must have the right length');
t.equal(buf.readUInt8(0), 0xde, 'must have the proper header');
t.equal(buf.readUInt16BE(1), length, 'must include the map length');
t.equal(buf.length, computeLength(length), 'must have the right length')
t.equal(buf.readUInt8(0), 0xde, 'must have the proper header')
t.equal(buf.readUInt16BE(1), length, 'must include the map length')
t.end()
})
t.test('mirror test for a map of length ' + length + ' with ' + map[base], function(t) {
t.deepEqual(encoder.decode(buf), map, 'must stay the same');
t.test('mirror test for a map of length ' + length + ' with ' + map[base], function (t) {
t.deepEqual(encoder.decode(buf), map, 'must stay the same')
t.end()

@@ -60,3 +59,3 @@ })

test('decoding a chopped map', function(t) {
test('decoding a chopped map', function (t) {
var encoder = msgpack()

@@ -70,8 +69,10 @@ var map = encoder.encode(build(Math.pow(2, 12) + 1, 42))

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of a map', function(t) {
test('decoding an incomplete header of a map', function (t) {
var encoder = msgpack()

@@ -82,5 +83,7 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,11 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode 2^8 <-> (2^16-1) bytes strings', function(t) {
test('encode/decode 2^8 <-> (2^16-1) bytes strings', function (t) {
var encoder = msgpack()
, all = []
, str
var all = []
var str

@@ -28,13 +28,13 @@ str = new Buffer(Math.pow(2, 8))

all.forEach(function(str) {
t.test('encoding a string of length ' + str.length, function(t) {
all.forEach(function (str) {
t.test('encoding a string of length ' + str.length, function (t) {
var buf = encoder.encode(str)
t.equal(buf.length, 3 + Buffer.byteLength(str), 'must be the proper length')
t.equal(buf[0], 0xda, 'must have the proper header');
t.equal(buf.readUInt16BE(1), Buffer.byteLength(str), 'must include the str length');
t.equal(buf.toString('utf8', 3, Buffer.byteLength(str) + 3), str, 'must decode correctly');
t.equal(buf[0], 0xda, 'must have the proper header')
t.equal(buf.readUInt16BE(1), Buffer.byteLength(str), 'must include the str length')
t.equal(buf.toString('utf8', 3, Buffer.byteLength(str) + 3), str, 'must decode correctly')
t.end()
})
t.test('decoding a string of length ' + str.length, function(t) {
t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(3 + Buffer.byteLength(str))

@@ -44,8 +44,8 @@ buf[0] = 0xda

buf.write(str, 3)
t.equal(encoder.decode(buf), str, 'must decode correctly');
t.equal(encoder.decode(buf), str, 'must decode correctly')
t.end()
})
t.test('mirror test a string of length ' + str.length, function(t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same');
t.test('mirror test a string of length ' + str.length, function (t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same')
t.end()

@@ -58,5 +58,5 @@ })

test('decoding a chopped string', function(t) {
test('decoding a chopped string', function (t) {
var encoder = msgpack()
var str;
var str
for (str = 'a'; str.length < 0xff + 100; str += 'a') {

@@ -70,8 +70,10 @@ }

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of a string', function(t) {
test('decoding an incomplete header of a string', function (t) {
var encoder = msgpack()

@@ -82,5 +84,7 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,38 +1,36 @@

'use strict'
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
test('encode/decode strings with max 31 of length', function(t) {
test('encode/decode strings with max 31 of length', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
// build base
for (i = 'a'; i.length < 32; i += 'a') {
for (var i = 'a'; i.length < 32; i += 'a') {
all.push(i)
}
all.forEach(function(str) {
t.test('encoding a string of length ' + str.length, function(t) {
all.forEach(function (str) {
t.test('encoding a string of length ' + str.length, function (t) {
var buf = encoder.encode(str)
t.equal(buf.length, 1 + Buffer.byteLength(str), 'must be the proper length')
t.equal(buf.readUInt8(0) & 0xe0, 0xa0, 'must have the proper header');
t.equal(buf.readUInt8(0) & 0x1f, Buffer.byteLength(str), 'must include the str length');
t.equal(buf.toString('utf8', 1, Buffer.byteLength(str) + 2), str, 'must decode correctly');
t.equal(buf.readUInt8(0) & 0xe0, 0xa0, 'must have the proper header')
t.equal(buf.readUInt8(0) & 0x1f, Buffer.byteLength(str), 'must include the str length')
t.equal(buf.toString('utf8', 1, Buffer.byteLength(str) + 2), str, 'must decode correctly')
t.end()
})
t.test('decoding a string of length ' + str.length, function(t) {
t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(1 + Buffer.byteLength(str))
buf[0] = 0xa0 | Buffer.byteLength(str)
buf.write(str, 1)
t.equal(encoder.decode(buf), str, 'must decode correctly');
t.equal(encoder.decode(buf), str, 'must decode correctly')
t.end()
})
t.test('mirror test a string of length ' + str.length, function(t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same');
t.test('mirror test a string of length ' + str.length, function (t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same')
t.end()

@@ -45,3 +43,3 @@ })

test('decoding a chopped string', function(t) {
test('decoding a chopped string', function (t) {
var encoder = msgpack()

@@ -54,5 +52,7 @@ var str = 'aaa'

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,12 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 32-bits big-endian signed integers', function(t) {
test('encoding/decoding 32-bits big-endian signed integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 32769; i < 214748364; i += 10235023) {
for (var i = 32769; i < 214748364; i += 10235023) {
allNum.push(-i)

@@ -17,21 +17,21 @@ }

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 5, 'must have 5 bytes')
t.equal(buf[0], 0xd2, 'must have the proper header');
t.equal(buf.readInt32BE(1), num, 'must decode correctly');
t.equal(buf[0], 0xd2, 'must have the proper header')
t.equal(buf.readInt32BE(1), num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(5)
buf[0] = 0xd2
buf.writeInt32BE(num, 1)
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -44,3 +44,3 @@ })

test('decoding an incomplete 32-bits big-endian integer', function(t) {
test('decoding an incomplete 32-bits big-endian integer', function (t) {
var encoder = msgpack()

@@ -51,5 +51,7 @@ var buf = new Buffer(4)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,12 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 32-bits big-endian unsigned integers', function(t) {
test('encoding/decoding 32-bits big-endian unsigned integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 65536; i < 0xffffffff; i += 102350237) {
for (var i = 65536; i < 0xffffffff; i += 102350237) {
allNum.push(i)

@@ -18,21 +18,21 @@ }

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 5, 'must have 5 bytes')
t.equal(buf[0], 0xce, 'must have the proper header');
t.equal(buf.readUInt32BE(1), num, 'must decode correctly');
t.equal(buf[0], 0xce, 'must have the proper header')
t.equal(buf.readUInt32BE(1), num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(5)
buf[0] = 0xce
buf.writeUInt32BE(num, 1)
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -45,3 +45,3 @@ })

test('decoding an incomplete 32-bits big-endian unsigned integer', function(t) {
test('decoding an incomplete 32-bits big-endian unsigned integer', function (t) {
var encoder = msgpack()

@@ -52,5 +52,7 @@ var buf = new Buffer(4)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,34 +1,33 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encode/decode up to 31 bytes strings', function(t) {
test('encode/decode up to 31 bytes strings', function (t) {
var encoder = msgpack()
, all = []
, i
var all = []
for (i = 'a'; i.length < 32; i += 'a') {
for (var i = 'a'; i.length < 32; i += 'a') {
all.push(i)
}
all.forEach(function(str) {
t.test('encoding a string of length ' + str.length, function(t) {
all.forEach(function (str) {
t.test('encoding a string of length ' + str.length, function (t) {
var buf = encoder.encode(str)
t.equal(buf.length, 1 + Buffer.byteLength(str), 'must have 2 bytes')
t.equal(buf[0] & 0xe0, 0xa0, 'must have the proper header');
t.equal(buf.toString('utf8', 1, Buffer.byteLength(str) + 1), str, 'must decode correctly');
t.equal(buf[0] & 0xe0, 0xa0, 'must have the proper header')
t.equal(buf.toString('utf8', 1, Buffer.byteLength(str) + 1), str, 'must decode correctly')
t.end()
})
t.test('decoding a string of length ' + str.length, function(t) {
t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(1 + Buffer.byteLength(str))
buf[0] = 0xa0 | Buffer.byteLength(str)
buf.write(str, 1)
t.equal(encoder.decode(buf), str, 'must decode correctly');
t.equal(encoder.decode(buf), str, 'must decode correctly')
t.end()
})
t.test('mirror test a string of length ' + str.length, function(t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same');
t.test('mirror test a string of length ' + str.length, function (t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same')
t.end()

@@ -35,0 +34,0 @@ })

@@ -0,11 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var array = []
, i
for(i = 0; i < size; i++) {
for (var i = 0; i < size; i++) {
array.push(42)

@@ -17,18 +17,17 @@ }

test('encode/decode arrays up to 0xffffffff elements', function(t) {
test('encode/decode arrays up to 0xffffffff elements', function (t) {
var encoder = msgpack()
function doTest(array) {
t.test('encoding an array with ' + array.length + ' elements', function(t) {
function doTest (array) {
t.test('encoding an array with ' + array.length + ' elements', function (t) {
var buf = encoder.encode(array)
// the array is full of 1-byte integers
t.equal(buf.length, 5 + array.length, 'must have the right length');
t.equal(buf.readUInt8(0), 0xdd, 'must have the proper header');
t.equal(buf.readUInt32BE(1), array.length, 'must include the array length');
t.equal(buf.length, 5 + array.length, 'must have the right length')
t.equal(buf.readUInt8(0), 0xdd, 'must have the proper header')
t.equal(buf.readUInt32BE(1), array.length, 'must include the array length')
t.end()
})
t.test('mirror test for an array of length ' + array.length, function(t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same');
t.test('mirror test for an array of length ' + array.length, function (t) {
t.deepEqual(encoder.decode(encoder.encode(array)), array, 'must stay the same')
t.end()

@@ -45,3 +44,3 @@ })

test('decoding an incomplete array', function(t) {
test('decoding an incomplete array', function (t) {
var encoder = msgpack()

@@ -61,8 +60,10 @@

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header', function(t) {
test('decoding an incomplete header', function (t) {
var encoder = msgpack()

@@ -74,5 +75,7 @@

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,7 +1,8 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var buf

@@ -15,6 +16,5 @@

test('encode/decode 2^32-1 bytes buffers', function(t) {
test('encode/decode 2^32-1 bytes buffers', function (t) {
var encoder = msgpack()
, all = []
var all = []

@@ -25,13 +25,13 @@ all.push(build(Math.pow(2, 16)))

all.forEach(function(orig) {
t.test('encoding a buffer of length ' + orig.length, function(t) {
all.forEach(function (orig) {
t.test('encoding a buffer of length ' + orig.length, function (t) {
var buf = encoder.encode(orig)
t.equal(buf.length, 5 + orig.length, 'must have the right length');
t.equal(buf.readUInt8(0), 0xc6, 'must have the proper header');
t.equal(buf.readUInt32BE(1), orig.length, 'must include the buf length');
t.equal(buf.toString('utf8', 5), orig.toString('utf8'), 'must decode correctly');
t.equal(buf.length, 5 + orig.length, 'must have the right length')
t.equal(buf.readUInt8(0), 0xc6, 'must have the proper header')
t.equal(buf.readUInt32BE(1), orig.length, 'must include the buf length')
t.equal(buf.toString('utf8', 5), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('decoding a buffer of length ' + orig.length, function(t) {
t.test('decoding a buffer of length ' + orig.length, function (t) {
var buf = new Buffer(5 + orig.length)

@@ -41,8 +41,8 @@ buf[0] = 0xc6

orig.copy(buf, 5)
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly');
t.equal(encoder.decode(buf).toString('utf8'), orig.toString('utf8'), 'must decode correctly')
t.end()
})
t.test('mirror test a buffer of length ' + orig.length, function(t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same');
t.test('mirror test a buffer of length ' + orig.length, function (t) {
t.equal(encoder.decode(encoder.encode(orig)).toString(), orig.toString(), 'must stay the same')
t.end()

@@ -55,17 +55,19 @@ })

test('decoding a chopped 2^32-1 bytes buffer', function(t) {
test('decoding a chopped 2^32-1 bytes buffer', function (t) {
var encoder = msgpack()
var orig = build(Math.pow(2,18))
var orig = build(Math.pow(2, 18))
var buf = new Buffer(5 + orig.length)
buf[0] = 0xc6
buf[1] = Math.pow(2,32) - 1 // set bigger size
buf[1] = Math.pow(2, 32) - 1 // set bigger size
orig.copy(buf, 5)
buf = bl().append(buf)
var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of 2^32-1 bytes buffer', function(t) {
test('decoding an incomplete header of 2^32-1 bytes buffer', function (t) {
var encoder = msgpack()

@@ -76,5 +78,7 @@ var buf = new Buffer(4)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,17 +1,17 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode variable ext data up between 0x10000 and 0xffffffff', function(t) {
test('encode/decode variable ext data up between 0x10000 and 0xffffffff', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(size, value) {
function MyType (size, value) {
this.value = value
this.size = size
this.size = size
}
function mytipeEncode(obj) {
function mytipeEncode (obj) {
var buf = new Buffer(obj.size)

@@ -22,8 +22,7 @@ buf.fill(obj.value)

function mytipeDecode(data) {
function mytipeDecode (data) {
var result = new MyType(data.length, data.toString('utf8', 0, 1))
, i
for (i = 0; i < data.length; i++) {
if (data.readUInt8(0) != data.readUInt8(i)) {
for (var i = 0; i < data.length; i++) {
if (data.readUInt8(0) !== data.readUInt8(i)) {
throw new Error('should all be the same')

@@ -42,4 +41,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj of length ' + orig.size, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj of length ' + orig.size, function (t) {
var buf = encoder.encode(orig)

@@ -54,3 +53,3 @@ t.equal(buf.length, 6 + orig.size, 'must have the right length')

t.test('mirror test with a custom obj of length ' + orig.size, function(t) {
t.test('mirror test with a custom obj of length ' + orig.size, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -61,3 +60,3 @@ t.end()

t.test('decoding an incomplete variable ext data up between 0x10000 and 0xffffffff', function(t) {
t.test('decoding an incomplete variable ext data up between 0x10000 and 0xffffffff', function (t) {
var obj = encoder.encode(new MyType(0xffffff, 'a'))

@@ -70,8 +69,10 @@ var buf = new Buffer(obj.length)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete header of variable ext data up between 0x10000 and 0xffffffff', function(t) {
t.test('decoding an incomplete header of variable ext data up between 0x10000 and 0xffffffff', function (t) {
var buf = new Buffer(5)

@@ -81,4 +82,6 @@ buf[0] = 0xc9

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()

@@ -85,0 +88,0 @@ })

@@ -0,11 +1,11 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode 2^16 <-> (2^32 - 1) bytes strings', function(t) {
test('encode/decode 2^16 <-> (2^32 - 1) bytes strings', function (t) {
var encoder = msgpack()
, all = []
, str
var all = []
var str

@@ -24,13 +24,13 @@ str = new Buffer(Math.pow(2, 16))

all.forEach(function(str) {
t.test('encoding a string of length ' + str.length, function(t) {
all.forEach(function (str) {
t.test('encoding a string of length ' + str.length, function (t) {
var buf = encoder.encode(str)
t.equal(buf.length, 5 + Buffer.byteLength(str), 'must be the proper length')
t.equal(buf[0], 0xdb, 'must have the proper header');
t.equal(buf.readUInt32BE(1), Buffer.byteLength(str), 'must include the str length');
t.equal(buf.toString('utf8', 5, Buffer.byteLength(str) + 5), str, 'must decode correctly');
t.equal(buf[0], 0xdb, 'must have the proper header')
t.equal(buf.readUInt32BE(1), Buffer.byteLength(str), 'must include the str length')
t.equal(buf.toString('utf8', 5, Buffer.byteLength(str) + 5), str, 'must decode correctly')
t.end()
})
t.test('decoding a string of length ' + str.length, function(t) {
t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(5 + Buffer.byteLength(str))

@@ -40,8 +40,8 @@ buf[0] = 0xdb

buf.write(str, 5)
t.equal(encoder.decode(buf), str, 'must decode correctly');
t.equal(encoder.decode(buf), str, 'must decode correctly')
t.end()
})
t.test('mirror test a string of length ' + str.length, function(t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same');
t.test('mirror test a string of length ' + str.length, function (t) {
t.equal(encoder.decode(encoder.encode(str)), str, 'must stay the same')
t.end()

@@ -54,5 +54,5 @@ })

test('decoding a chopped string', function(t) {
test('decoding a chopped string', function (t) {
var encoder = msgpack()
var str;
var str
for (str = 'a'; str.length < 0xffff + 100; str += 'a') {

@@ -66,8 +66,10 @@ }

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding an incomplete header of a string', function(t) {
test('decoding an incomplete header of a string', function (t) {
var encoder = msgpack()

@@ -78,5 +80,7 @@ var buf = new Buffer(4)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,30 +1,30 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encoding/decoding 5-bits negative ints', function(t) {
test('encoding/decoding 5-bits negative ints', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 1; i <= 32; i++) {
for (var i = 1; i <= 32; i++) {
allNum.push(-i)
}
allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 1, 'must have 1 byte')
t.equal(buf[0], num + 0x100, 'must encode correctly');
t.equal(buf[0], num + 0x100, 'must encode correctly')
t.end()
})
t.test('decoding' + num, function(t) {
t.test('decoding' + num, function (t) {
var buf = new Buffer([num + 0x100])
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -31,0 +31,0 @@ })

@@ -0,19 +1,19 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 64-bits big-endian signed integers', function(t) {
test('encoding/decoding 64-bits big-endian signed integers', function (t) {
var encoder = msgpack()
, table = [
{ num: -9007199254740991, hi: 0xffe00000, lo: 0x00000001 },
{ num: -4294967297, hi: 0xfffffffe, lo: 0xffffffff },
{ num: -4294967296, hi: 0xffffffff, lo: 0x00000000 },
{ num: -4294967295, hi: 0xffffffff, lo: 0x00000001 },
{ num: -214748365, hi: 0xffffffff, lo: 0xf3333333 },
]
var table = [
{ num: -9007199254740991, hi: 0xffe00000, lo: 0x00000001 },
{ num: -4294967297, hi: 0xfffffffe, lo: 0xffffffff },
{ num: -4294967296, hi: 0xffffffff, lo: 0x00000000 },
{ num: -4294967295, hi: 0xffffffff, lo: 0x00000001 },
{ num: -214748365, hi: 0xffffffff, lo: 0xf3333333 }
]
table.forEach(function(testCase) {
t.test('encoding ' + testCase.num, function(t) {
table.forEach(function (testCase) {
t.test('encoding ' + testCase.num, function (t) {
var buf = encoder.encode(testCase.num)

@@ -27,4 +27,4 @@ t.equal(buf.length, 9, 'must have 9 bytes')

t.test('mirror test ' + testCase.num, function(t) {
t.equal(encoder.decode(encoder.encode(testCase.num)), testCase.num, 'must stay the same');
t.test('mirror test ' + testCase.num, function (t) {
t.equal(encoder.decode(encoder.encode(testCase.num)), testCase.num, 'must stay the same')
t.end()

@@ -37,3 +37,3 @@ })

test('decoding an incomplete 64-bits big-endian signed integer', function(t) {
test('decoding an incomplete 64-bits big-endian signed integer', function (t) {
var encoder = msgpack()

@@ -44,5 +44,7 @@ var buf = new Buffer(8)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,29 +1,29 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 64-bits big-endian unsigned integers', function(t) {
test('encoding/decoding 64-bits big-endian unsigned integers', function (t) {
var encoder = msgpack()
, allNum = []
var allNum = []
allNum.push(0x0000000100000000)
allNum.push(0xffffffffeeeee)
allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 9, 'must have 9 bytes')
t.equal(buf[0], 0xcf, 'must have the proper header')
var result = 0;
var result = 0
for (var k = 7; k >= 0; k--) {
result += (buf.readUInt8(k + 1) * Math.pow(2 , (8 *(7-k))));
}
t.equal(result, num, 'must decode correctly');
result += (buf.readUInt8(k + 1) * Math.pow(2, (8 * (7 - k))))
}
t.equal(result, num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -36,3 +36,3 @@ })

test('decoding an incomplete 64-bits big-endian unsigned integer', function(t) {
test('decoding an incomplete 64-bits big-endian unsigned integer', function (t) {
var encoder = msgpack()

@@ -43,5 +43,7 @@ var buf = new Buffer(8)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,30 +1,30 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encoding/decoding 7-bits positive ints', function(t) {
test('encoding/decoding 7-bits positive ints', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 0; i < 126; i++) {
for (var i = 0; i < 126; i++) {
allNum.push(i)
}
allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 1, 'must have 1 byte')
t.equal(buf[0], num, 'must decode correctly');
t.equal(buf[0], num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer([num])
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -31,0 +31,0 @@ })

@@ -0,32 +1,32 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 8-bits integers', function(t) {
test('encoding/decoding 8-bits integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 128; i < 256; i++) {
for (var i = 128; i < 256; i++) {
allNum.push(i)
}
allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 2, 'must have 2 bytes')
t.equal(buf[0], 0xcc, 'must have the proper header');
t.equal(buf[1], num, 'must decode correctly');
t.equal(buf[0], 0xcc, 'must have the proper header')
t.equal(buf[1], num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer([0xcc, num])
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -39,3 +39,3 @@ })

test('decoding an incomplete 8-bits unsigned integer', function(t) {
test('decoding an incomplete 8-bits unsigned integer', function (t) {
var encoder = msgpack()

@@ -46,5 +46,7 @@ var buf = new Buffer(1)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,34 +1,34 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 8-bits big-endian signed integers', function(t) {
test('encoding/decoding 8-bits big-endian signed integers', function (t) {
var encoder = msgpack()
, allNum = []
, i
var allNum = []
for (i = 33; i <= 128; i++) {
for (var i = 33; i <= 128; i++) {
allNum.push(-i)
}
allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
t.equal(buf.length, 2, 'must have 2 bytes')
t.equal(buf[0], 0xd0, 'must have the proper header');
t.equal(buf.readInt8(1), num, 'must decode correctly');
t.equal(buf[0], 0xd0, 'must have the proper header')
t.equal(buf.readInt8(1), num, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(3)
buf[0] = 0xd0
buf.writeInt8(num, 1)
t.equal(encoder.decode(buf), num, 'must decode correctly');
t.equal(encoder.decode(buf), num, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same');
t.test('mirror test ' + num, function (t) {
t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
t.end()

@@ -41,3 +41,3 @@ })

test('decoding an incomplete 8-bits big-endian signed integer', function(t) {
test('decoding an incomplete 8-bits big-endian signed integer', function (t) {
var encoder = msgpack()

@@ -48,5 +48,7 @@ var buf = new Buffer(1)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,20 +1,20 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encode/decode booleans', function(t) {
test('encode/decode booleans', function (t) {
var encoder = msgpack()
t.equal(encoder.encode(true)[0], 0xc3, 'encode true as 0xc3');
t.equal(encoder.encode(true).length, 1, 'encode true as a buffer of length 1');
t.equal(encoder.decode(new Buffer([0xc3])), true, 'decode 0xc3 as true');
t.equal(encoder.decode(encoder.encode(true)), true, 'mirror test true');
t.equal(encoder.encode(true)[0], 0xc3, 'encode true as 0xc3')
t.equal(encoder.encode(true).length, 1, 'encode true as a buffer of length 1')
t.equal(encoder.decode(new Buffer([0xc3])), true, 'decode 0xc3 as true')
t.equal(encoder.decode(encoder.encode(true)), true, 'mirror test true')
t.equal(encoder.encode(false)[0], 0xc2, 'encode false as 0xc2');
t.equal(encoder.encode(false).length, 1, 'encode false as a buffer of length 1');
t.equal(encoder.decode(new Buffer([0xc2])), false, 'decode 0xc2 as false');
t.equal(encoder.decode(encoder.encode(false)), false, 'mirror test false');
t.equal(encoder.encode(false)[0], 0xc2, 'encode false as 0xc2')
t.equal(encoder.encode(false).length, 1, 'encode false as a buffer of length 1')
t.equal(encoder.decode(new Buffer([0xc2])), false, 'decode 0xc2 as false')
t.equal(encoder.decode(encoder.encode(false)), false, 'mirror test false')
t.end()
})

@@ -0,9 +1,10 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 64-bits float numbers', function(t) {
test('encoding/decoding 64-bits float numbers', function (t) {
var encoder = msgpack()
, allNum = []
var allNum = []

@@ -15,25 +16,25 @@ allNum.push(748365544534.2)

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
, dec = buf.readDoubleBE(1)
var dec = buf.readDoubleBE(1)
t.equal(buf.length, 9, 'must have 9 bytes')
t.equal(buf[0], 0xcb, 'must have the proper header');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.equal(buf[0], 0xcb, 'must have the proper header')
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(9)
, dec
var dec
buf[0] = 0xcb
buf.writeDoubleBE(num, 1)
dec = encoder.decode(buf)
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.test('mirror test ' + num, function (t) {
var dec = encoder.decode(encoder.encode(num))
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()

@@ -46,3 +47,3 @@ })

test('decoding an incomplete 64-bits float numbers', function(t) {
test('decoding an incomplete 64-bits float numbers', function (t) {
var encoder = msgpack()

@@ -53,5 +54,7 @@ var buf = new Buffer(8)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,19 +1,19 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encode/decode ext with a custom object check', function(t) {
test('encode/decode ext with a custom object check', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function checkForMyType(obj) {
function checkForMyType (obj) {
return obj instanceof MyType
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(2)

@@ -25,3 +25,3 @@ buf.writeUInt8(0x42, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt8(0))

@@ -37,4 +37,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -48,3 +48,3 @@ t.equal(buf.length, 3, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(3)

@@ -59,3 +59,3 @@ buf[0] = 0xd4

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -62,0 +62,0 @@ t.end()

@@ -0,16 +1,16 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encode/decode 1 byte fixext data', function(t) {
test('encode/decode 1 byte fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(1)

@@ -21,3 +21,3 @@ buf.writeUInt8(obj.data, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt8(0))

@@ -32,4 +32,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -43,3 +43,3 @@ t.equal(buf.length, 3, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(3)

@@ -54,3 +54,3 @@ buf[0] = 0xd4

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -64,12 +64,11 @@ t.end()

test('encode/decode 2 bytes fixext data', function(t) {
test('encode/decode 2 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(2)

@@ -80,3 +79,3 @@ buf.writeUInt16BE(obj.data, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt16BE(0))

@@ -91,4 +90,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -102,3 +101,3 @@ t.equal(buf.length, 4, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(4)

@@ -113,3 +112,3 @@ buf[0] = 0xd5

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -123,12 +122,11 @@ t.end()

test('encode/decode 4 bytes fixext data', function(t) {
test('encode/decode 4 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(4)

@@ -139,3 +137,3 @@ buf.writeUInt32BE(obj.data, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0))

@@ -150,4 +148,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -161,3 +159,3 @@ t.equal(buf.length, 6, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(6)

@@ -172,3 +170,3 @@ buf[0] = 0xd6

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -182,12 +180,11 @@ t.end()

test('encode/decode 8 bytes fixext data', function(t) {
test('encode/decode 8 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(8)

@@ -199,3 +196,3 @@ buf.writeUInt32BE(obj.data / 2, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0) + data.readUInt32BE(4))

@@ -210,4 +207,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -221,3 +218,3 @@ t.equal(buf.length, 10, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(10)

@@ -233,3 +230,3 @@ buf[0] = 0xd7

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -243,12 +240,11 @@ t.end()

test('encode/decode 16 bytes fixext data', function(t) {
test('encode/decode 16 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(16)

@@ -262,3 +258,3 @@ buf.writeUInt32BE(obj.data / 4, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0) + data.readUInt32BE(4) + data.readUInt32BE(8) + data.readUInt32BE(12))

@@ -273,4 +269,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -284,3 +280,3 @@ t.equal(buf.length, 18, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(18)

@@ -298,3 +294,3 @@ buf[0] = 0xd8

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -308,12 +304,11 @@ t.end()

test('encode/decode fixext inside a map', function(t) {
test('encode/decode fixext inside a map', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(4)

@@ -324,3 +319,3 @@ buf.writeUInt32BE(obj.data, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0))

@@ -334,3 +329,3 @@ }

all.push([1,2,3,4,5, 6].reduce(function(acc, key) {
all.push([1, 2, 3, 4, 5, 6].reduce(function (acc, key) {
acc[key] = new MyType(key)

@@ -340,4 +335,4 @@ return acc

all.forEach(function(orig) {
t.test('mirror test with a custom obj inside a map', function(t) {
all.forEach(function (orig) {
t.test('mirror test with a custom obj inside a map', function (t) {
var encoded = encoder.encode(orig)

@@ -352,12 +347,11 @@ t.deepEqual(encoder.decode(encoded), orig, 'must stay the same')

test('encode/decode 8 bytes fixext data', function(t) {
test('encode/decode 8 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(8)

@@ -369,3 +363,3 @@ buf.writeUInt32BE(obj.data / 2, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0) + data.readUInt32BE(4))

@@ -380,4 +374,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -391,3 +385,3 @@ t.equal(buf.length, 10, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(10)

@@ -403,3 +397,3 @@ buf[0] = 0xd7

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -413,12 +407,11 @@ t.end()

test('encode/decode 16 bytes fixext data', function(t) {
test('encode/decode 16 bytes fixext data', function (t) {
var encoder = msgpack()
, all = []
var all = []
function MyType(data) {
function MyType (data) {
this.data = data
}
function mytypeEncode(obj) {
function mytypeEncode (obj) {
var buf = new Buffer(16)

@@ -432,3 +425,3 @@ buf.writeUInt32BE(obj.data / 4, 0)

function mytypeDecode(data) {
function mytypeDecode (data) {
return new MyType(data.readUInt32BE(0) + data.readUInt32BE(4) + data.readUInt32BE(8) + data.readUInt32BE(12))

@@ -443,4 +436,4 @@ }

all.forEach(function(orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function(t) {
all.forEach(function (orig) {
t.test('encoding a custom obj encoded as ' + orig.data, function (t) {
var buf = encoder.encode(orig)

@@ -454,3 +447,3 @@ t.equal(buf.length, 18, 'must have the right length')

t.test('decoding a custom obj encoded as ' + orig.data, function(t) {
t.test('decoding a custom obj encoded as ' + orig.data, function (t) {
var buf = new Buffer(18)

@@ -468,3 +461,3 @@ buf[0] = 0xd8

t.test('mirror test with a custom obj containing ' + orig.data, function(t) {
t.test('mirror test with a custom obj containing ' + orig.data, function (t) {
t.deepEqual(encoder.decode(encoder.encode(orig)), orig, 'must stay the same')

@@ -475,3 +468,3 @@ t.end()

t.test('decoding an incomplete 1 byte fixext data', function(t) {
t.test('decoding an incomplete 1 byte fixext data', function (t) {
var encoder = msgpack()

@@ -482,8 +475,10 @@ var buf = new Buffer(2)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete 2 byte fixext data', function(t) {
t.test('decoding an incomplete 2 byte fixext data', function (t) {
var encoder = msgpack()

@@ -494,8 +489,10 @@ var buf = new Buffer(3)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete 4 byte fixext data', function(t) {
t.test('decoding an incomplete 4 byte fixext data', function (t) {
var encoder = msgpack()

@@ -506,8 +503,10 @@ var buf = new Buffer(5)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete 8 byte fixext data', function(t) {
t.test('decoding an incomplete 8 byte fixext data', function (t) {
var encoder = msgpack()

@@ -518,8 +517,10 @@ var buf = new Buffer(9)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
t.test('decoding an incomplete 16 byte fixext data', function(t) {
t.test('decoding an incomplete 16 byte fixext data', function (t) {
var encoder = msgpack()

@@ -530,4 +531,6 @@ var buf = new Buffer(17)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()

@@ -534,0 +537,0 @@ })

@@ -0,9 +1,10 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
test('encoding/decoding 32-bits float numbers', function(t) {
test('encoding/decoding 32-bits float numbers', function (t) {
var encoder = msgpack()
, allNum = []
var allNum = []

@@ -14,35 +15,35 @@ allNum.push(-222.42)

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
allNum.forEach(function (num) {
t.test('encoding ' + num, function (t) {
var buf = encoder.encode(num)
, dec = buf.readFloatBE(1)
var dec = buf.readFloatBE(1)
t.equal(buf.length, 5, 'must have 5 bytes')
t.equal(buf[0], 0xca, 'must have the proper header');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.equal(buf[0], 0xca, 'must have the proper header')
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()
})
t.test('forceFloat64 encoding ' + num, function(t) {
t.test('forceFloat64 encoding ' + num, function (t) {
var enc = msgpack({ forceFloat64: true })
, buf = enc.encode(num)
, dec = buf.readDoubleBE(1)
var buf = enc.encode(num)
var dec = buf.readDoubleBE(1)
t.equal(buf.length, 9, 'must have 9 bytes')
t.equal(buf[0], 0xcb, 'must have the proper header');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.equal(buf[0], 0xcb, 'must have the proper header')
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()
})
t.test('decoding ' + num, function(t) {
t.test('decoding ' + num, function (t) {
var buf = new Buffer(5)
, dec
var dec
buf[0] = 0xca
buf.writeFloatBE(num, 1)
dec = encoder.decode(buf)
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()
})
t.test('mirror test ' + num, function(t) {
t.test('mirror test ' + num, function (t) {
var dec = encoder.decode(encoder.encode(num))
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly');
t.true(Math.abs(dec - num) < 0.1, 'must decode correctly')
t.end()

@@ -55,3 +56,3 @@ })

test('decoding an incomplete 32-bits float numbers', function(t) {
test('decoding an incomplete 32-bits float numbers', function (t) {
var encoder = msgpack()

@@ -62,5 +63,7 @@ var buf = new Buffer(4)

var origLength = buf.length
t.throws(function() {encoder.decode(buf)}, encoder.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
encoder.decode(buf)
}, encoder.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,18 +1,19 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, noop = function() {}
var test = require('tape').test
var msgpack = require('../')
var noop = function () {}
test('encode a function inside a map', function(t) {
var encoder = msgpack()
, expected = {
hello: 'world'
}
, toEncode = {
hello: 'world'
, func: noop
}
test('encode a function inside a map', function (t) {
var encoder = msgpack()
var expected = {
hello: 'world'
}
var toEncode = {
hello: 'world',
func: noop
}
t.deepEqual(encoder.decode(encoder.encode(toEncode)), expected, 'remove the function from the map');
t.deepEqual(encoder.decode(encoder.encode(toEncode)), expected, 'remove the function from the map')
t.end()
})

@@ -0,21 +1,22 @@

'use strict'
var test = require('tape').test
, level = require('level-test')()
, msgpack = require('../')
var test = require('tape').test
var level = require('level-test')()
var msgpack = require('../')
test('msgpack level encoding put', function(t) {
test('msgpack level encoding put', function (t) {
t.plan(4)
var pack = msgpack()
, db = level('foo', {
valueEncoding: pack
})
, obj = { my: 'obj' }
var pack = msgpack()
var db = level('foo', {
valueEncoding: pack
})
var obj = { my: 'obj' }
db.put('hello', obj, function(err) {
db.put('hello', obj, function (err) {
t.error(err, 'put has no errors')
db.get('hello', { valueEncoding: 'binary'}, function(err, buf) {
db.get('hello', { valueEncoding: 'binary' }, function (err, buf) {
t.error(err, 'get has no error')
t.deepEqual(pack.decode(buf), obj)
db.close(function() {
db.close(function () {
t.pass('db closed')

@@ -27,18 +28,18 @@ })

test('msgpack level encoding get', function(t) {
test('msgpack level encoding get', function (t) {
t.plan(4)
var pack = msgpack()
, db = level('foo', {
valueEncoding: pack
})
, obj = { my: 'obj' }
, buf = pack.encode(obj)
var pack = msgpack()
var db = level('foo', {
valueEncoding: pack
})
var obj = { my: 'obj' }
var buf = pack.encode(obj)
db.put('hello', buf, { valueEncoding: 'binary'}, function(err) {
db.put('hello', buf, { valueEncoding: 'binary' }, function (err) {
t.error(err, 'putting has no errors')
db.get('hello', function(err, result) {
db.get('hello', function (err, result) {
t.error(err, 'get has no error')
t.deepEqual(result, obj)
db.close(function() {
db.close(function () {
t.pass('db closed')

@@ -50,17 +51,17 @@ })

test('msgpack level encoding mirror', function(t) {
test('msgpack level encoding mirror', function (t) {
t.plan(4)
var pack = msgpack()
, db = level('foo', {
valueEncoding: pack
})
, obj = { my: 'obj' }
var pack = msgpack()
var db = level('foo', {
valueEncoding: pack
})
var obj = { my: 'obj' }
db.put('hello', obj, function(err) {
db.put('hello', obj, function (err) {
t.error(err, 'putting has no errors')
db.get('hello', function(err, result) {
db.get('hello', function (err, result) {
t.error(err, 'get has no error')
t.deepEqual(result, obj)
db.close(function() {
db.close(function () {
t.pass('db closed')

@@ -67,0 +68,0 @@ })

@@ -0,14 +1,15 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('encode/decode null', function(t) {
test('encode/decode null', function (t) {
var encoder = msgpack()
t.equal(encoder.encode(null)[0], 0xc0, 'encode null as 0xc0');
t.equal(encoder.encode(null).length, 1, 'encode a buffer of length 1');
t.equal(encoder.decode(new Buffer([0xc0])), null, 'decode 0xc0 as null');
t.equal(encoder.decode(encoder.encode(null)), null, 'mirror test null');
t.equal(encoder.encode(null)[0], 0xc0, 'encode null as 0xc0')
t.equal(encoder.encode(null).length, 1, 'encode a buffer of length 1')
t.equal(encoder.decode(new Buffer([0xc0])), null, 'decode 0xc0 as null')
t.equal(encoder.decode(encoder.encode(null)), null, 'mirror test null')
t.end()
})

@@ -0,49 +1,49 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
var test = require('tape').test
var msgpack = require('../')
test('custom type registeration assertions', function(t) {
test('custom type registeration assertions', function (t) {
var encoder = msgpack()
function Type0(value) {
this.value = value;
function Type0 (value) {
this.value = value
}
function type0Encode(value) {
return new Type0(value);
function type0Encode (value) {
return new Type0(value)
}
function type0Decode(type0) {
return type0.value;
function type0Decode (type0) {
return type0.value
}
function TypeNeg(value) {
this.value = value;
function TypeNeg (value) {
this.value = value
}
function typeNegEncode(value) {
return new TypeNeg(value);
function typeNegEncode (value) {
return new TypeNeg(value)
}
function typeNegDecode(typeneg) {
return typeneg.value;
function typeNegDecode (typeneg) {
return typeneg.value
}
t.doesNotThrow(function () {
encoder.register(0, Type0, type0Decode, type0Encode);
}, undefined, "A type registered at 0 should not throw.");
encoder.register(0, Type0, type0Decode, type0Encode)
}, undefined, 'A type registered at 0 should not throw.')
t.throws(function () {
encoder.register(-1, TypeNeg, typeNegEncode, typeNegDecode);
}, undefined, "A type registered as a negative value should throw");
encoder.register(-1, TypeNeg, typeNegEncode, typeNegDecode)
}, undefined, 'A type registered as a negative value should throw')
var encoded = encoder.encode(new Type0('hi'));
var decoded;
t.equal(encoded.readUInt8(1), 0x0, 'must use the custom type assigned');
var encoded = encoder.encode(new Type0('hi'))
var decoded
t.equal(encoded.readUInt8(1), 0x0, 'must use the custom type assigned')
t.doesNotThrow(function () {
decoded = encoder.decode(encoded);
}, undefined, "decoding custom 0 type should not throw");
t.equal(decoded instanceof Type0, true, 'must decode to custom type instance');
decoded = encoder.decode(encoded)
}, undefined, 'decoding custom 0 type should not throw')
t.equal(decoded instanceof Type0, true, 'must decode to custom type instance')
t.end()
})

@@ -0,11 +1,12 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, bl = require('bl')
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
function build(size) {
function build (size) {
var array = []
, i
var i
for(i = 0; i < size; i++) {
for (i = 0; i < size; i++) {
array.push(42)

@@ -17,8 +18,8 @@ }

test('decoding a map with multiple big arrays', function(t) {
test('decoding a map with multiple big arrays', function (t) {
var map = {
first: build(0xffff + 42)
, second: build(0xffff + 42)
}
, pack = msgpack()
first: build(0xffff + 42),
second: build(0xffff + 42)
}
var pack = msgpack()

@@ -29,38 +30,42 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

test('decoding a map with multiple big arrays. First one is incomplete', function(t) {
test('decoding a map with multiple big arrays. First one is incomplete', function (t) {
var array = build(0xffff + 42)
var map = {
first: array
, second: build(0xffff + 42)
}
, pack = msgpack()
first: array,
second: build(0xffff + 42)
}
var pack = msgpack()
var buf = pack.encode(map)
// 1 (fixmap's header 0x82) + first key's length + 1 (first array's 0xdd)
var sizePosOfFirstArray = 1 + pack.encode("first").length + 1
var sizePosOfFirstArray = 1 + pack.encode('first').length + 1
buf.writeUInt32BE(array.length + 10, sizePosOfFirstArray) // set first array's size bigger than its actual size
buf = bl().append(buf)
var origLength = buf.length
t.throws(function() {pack.decode(buf)}, pack.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
pack.decode(buf)
}, pack.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})
test('decoding a map with multiple big arrays. Second one is incomplete', function(t) {
test('decoding a map with multiple big arrays. Second one is incomplete', function (t) {
var array = build(0xffff + 42)
var map = {
first: array
, second: build(0xffff + 42)
}
, pack = msgpack()
first: array,
second: build(0xffff + 42)
}
var pack = msgpack()
var buf = pack.encode(map)
// 1 (fixmap's header 0x82) + first key-value pair's length + second key's length + 1 (second array's 0xdd)
var sizePosOfSecondArray = 1 + pack.encode("first").length + pack.encode(array).length + pack.encode("second").length + 1
var sizePosOfSecondArray = 1 + pack.encode('first').length + pack.encode(array).length + pack.encode('second').length + 1
buf.writeUInt32BE(array.length + 10, sizePosOfSecondArray) // set second array's size bigger than its actual size
buf = bl().append(buf)
var origLength = buf.length
t.throws(function() {pack.decode(buf)}, pack.IncompleteBufferError, "must throw IncompleteBufferError")
t.equals(buf.length, origLength, "must not consume any byte")
t.throws(function () {
pack.decode(buf)
}, pack.IncompleteBufferError, 'must throw IncompleteBufferError')
t.equals(buf.length, origLength, 'must not consume any byte')
t.end()
})

@@ -0,13 +1,15 @@

'use strict'
var test = require('tape').test
, fs = require('fs')
, msgpack = require('../')
var test = require('tape').test
var fs = require('fs')
var p = require('path')
var msgpack = require('../')
test('encode/decode map with multiple short buffers', function(t) {
test('encode/decode map with multiple short buffers', function (t) {
var map = {
first: new Buffer('first')
, second: new Buffer('second')
, third: new Buffer('third')
}
, pack = msgpack()
first: new Buffer('first'),
second: new Buffer('second'),
third: new Buffer('third')
}
var pack = msgpack()

@@ -18,11 +20,10 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

if (process.title !== "browser") {
test('encode/decode map with all files in this directory', function(t) {
if (process.title !== 'browser') {
test('encode/decode map with all files in this directory', function (t) {
var files = fs.readdirSync(__dirname)
, map = files.reduce(function(acc, file) {
acc[file] = fs.readFileSync(__dirname + '/' + file)
return acc
}, {})
, pack = msgpack()
var map = files.reduce(function (acc, file) {
acc[file] = fs.readFileSync(p.join(__dirname, file))
return acc
}, {})
var pack = msgpack()

@@ -29,0 +30,0 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

@@ -0,13 +1,15 @@

'use strict'
var test = require('tape').test
, fs = require('fs')
, msgpack = require('../')
var test = require('tape').test
var fs = require('fs')
var p = require('path')
var msgpack = require('../')
test('encode/decode map with multiple short buffers', function(t) {
test('encode/decode map with multiple short buffers', function (t) {
var map = {
first: 'first'
, second: 'second'
, third: 'third'
}
, pack = msgpack()
first: 'first',
second: 'second',
third: 'third'
}
var pack = msgpack()

@@ -18,11 +20,10 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

if (process.title !== "browser") {
test('encode/decode map with all files in this directory', function(t) {
if (process.title !== 'browser') {
test('encode/decode map with all files in this directory', function (t) {
var files = fs.readdirSync(__dirname)
, map = files.reduce(function(acc, file) {
acc[file] = fs.readFileSync(__dirname + '/' + file).toString('utf8')
return acc
}, {})
, pack = msgpack()
var map = files.reduce(function (acc, file) {
acc[file] = fs.readFileSync(p.join(__dirname, file)).toString('utf8')
return acc
}, {})
var pack = msgpack()

@@ -29,0 +30,0 @@ t.deepEqual(pack.decode(pack.encode(map)), map)

@@ -0,17 +1,18 @@

'use strict'
var test = require('tape').test
, msgpack = require('../')
, BufferList = require('bl')
var test = require('tape').test
var msgpack = require('../')
var BufferList = require('bl')
test('must send an object through', function(t) {
test('must send an object through', function (t) {
t.plan(1)
var pack = msgpack()
, encoder = pack.encoder()
, decoder = pack.decoder()
, data = { hello: 'world' }
var pack = msgpack()
var encoder = pack.encoder()
var decoder = pack.decoder()
var data = { hello: 'world' }
encoder.pipe(decoder)
decoder.on('data', function(chunk) {
decoder.on('data', function (chunk) {
t.deepEqual(chunk, data)

@@ -23,15 +24,15 @@ })

test('must send three objects through', function(t) {
var pack = msgpack()
, encoder = pack.encoder()
, decoder = pack.decoder()
, data = [
{ hello: 1 }
, { hello: 2 }
, { hello: 3 }
]
test('must send three objects through', function (t) {
var pack = msgpack()
var encoder = pack.encoder()
var decoder = pack.decoder()
var data = [
{ hello: 1 },
{ hello: 2 },
{ hello: 3 }
]
t.plan(data.length)
decoder.on('data', function(chunk) {
decoder.on('data', function (chunk) {
t.deepEqual(chunk, data.shift())

@@ -47,15 +48,15 @@ })

test('end-to-end', function(t) {
var pack = msgpack()
, encoder = pack.encoder()
, decoder = pack.decoder()
, data = [
{ hello: 1 }
, { hello: 2 }
, { hello: 3 }
]
test('end-to-end', function (t) {
var pack = msgpack()
var encoder = pack.encoder()
var decoder = pack.decoder()
var data = [
{ hello: 1 },
{ hello: 2 },
{ hello: 3 }
]
t.plan(data.length)
decoder.on('data', function(chunk) {
decoder.on('data', function (chunk) {
t.deepEqual(chunk, data.shift())

@@ -71,17 +72,17 @@ })

test('encoding error wrapped', function(t) {
test('encoding error wrapped', function (t) {
t.plan(1)
var pack = msgpack()
, encoder = pack.encoder()
, data = new MyType()
var pack = msgpack()
var encoder = pack.encoder()
var data = new MyType()
function MyType() {
function MyType () {
}
function mytypeEncode() {
function mytypeEncode () {
throw new Error('muahha')
}
function mytypeDecode() {
function mytypeDecode () {
}

@@ -91,3 +92,3 @@

encoder.on('error', function(err) {
encoder.on('error', function (err) {
t.equal(err.message, 'muahha')

@@ -99,18 +100,18 @@ })

test('decoding error wrapped', function(t) {
test('decoding error wrapped', function (t) {
t.plan(1)
var pack = msgpack()
, encoder = pack.encoder()
, decoder = pack.decoder()
, data = new MyType()
var pack = msgpack()
var encoder = pack.encoder()
var decoder = pack.decoder()
var data = new MyType()
function MyType() {
function MyType () {
}
function mytypeEncode() {
function mytypeEncode () {
return new Buffer(0)
}
function mytypeDecode() {
function mytypeDecode () {
throw new Error('muahha')

@@ -121,3 +122,3 @@ }

decoder.on('error', function(err) {
decoder.on('error', function (err) {
t.equal(err.message, 'muahha')

@@ -131,18 +132,18 @@ })

test('decoding error wrapped', function(t) {
test('decoding error wrapped', function (t) {
t.plan(1)
var pack = msgpack()
, encoder = pack.encoder({ header: false })
, decoder = pack.decoder({ header: false })
, data = new MyType()
var pack = msgpack()
var encoder = pack.encoder({ header: false })
var decoder = pack.decoder({ header: false })
var data = new MyType()
function MyType() {
function MyType () {
}
function mytypeEncode() {
function mytypeEncode () {
return new Buffer(0)
}
function mytypeDecode() {
function mytypeDecode () {
throw new Error('muahha')

@@ -153,3 +154,3 @@ }

decoder.on('error', function(err) {
decoder.on('error', function (err) {
t.equal(err.message, 'muahha')

@@ -163,11 +164,11 @@ })

test('concatenated buffers work', function(t) {
var pack = msgpack()
, encoder = pack.encoder()
, decoder = pack.decoder()
, data = [
{ hello: 1 }
, { hello: 2 }
, { hello: 3 }
]
test('concatenated buffers work', function (t) {
var pack = msgpack()
var encoder = pack.encoder()
var decoder = pack.decoder()
var data = [
{ hello: 1 },
{ hello: 2 },
{ hello: 3 }
]

@@ -181,7 +182,7 @@ t.plan(data.length)

decoder.on('data', function(d) {
decoder.on('data', function (d) {
t.deepEqual(d, data.shift())
})
encoder.once('finish', function() {
encoder.once('finish', function () {
var buf = bl.slice()

@@ -188,0 +189,0 @@ decoder.write(buf)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc