msgpack5
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -8,3 +8,3 @@ | ||
function msgpack() { | ||
function msgpack(options) { | ||
@@ -14,2 +14,4 @@ var encodingTypes = [] | ||
options = options ? options : { forceFloat64: false } | ||
function registerEncoder(check, encode) { | ||
@@ -68,3 +70,3 @@ assert(check, 'must have an encode function') | ||
return { | ||
encode: buildEncode(encodingTypes) | ||
encode: buildEncode(encodingTypes, options.forceFloat64) | ||
, decode: buildDecode(decodingTypes) | ||
@@ -71,0 +73,0 @@ , register: register |
@@ -6,3 +6,5 @@ var bl = require('bl') | ||
Error.call(this); //super constructor | ||
Error.captureStackTrace(this, this.constructor); //super helper method to include stack trace in error object | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, this.constructor); //super helper method to include stack trace in error object | ||
} | ||
this.name = this.constructor.name | ||
@@ -9,0 +11,0 @@ this.message = message || "unable to decode" |
@@ -5,3 +5,3 @@ | ||
module.exports = function buildEncode(encodingTypes) { | ||
module.exports = function buildEncode(encodingTypes, forceFloat64) { | ||
function encode(obj, avoidSlice) { | ||
@@ -84,3 +84,3 @@ var buf | ||
if (isFloat(obj)) { | ||
return encodeFloat(obj) | ||
return encodeFloat(obj, forceFloat64) | ||
} else if (obj >= 0) { | ||
@@ -235,3 +235,3 @@ if (obj < 128) { | ||
function encodeFloat(obj) { | ||
function encodeFloat(obj, forceFloat64) { | ||
var buf | ||
@@ -245,3 +245,3 @@ | ||
// value fits in a float? | ||
if (Math.abs(obj - buf.readFloatBE(1)) > TOLERANCE) { | ||
if (forceFloat64 || Math.abs(obj - buf.readFloatBE(1)) > TOLERANCE) { | ||
buf = new Buffer(9) | ||
@@ -248,0 +248,0 @@ buf[0] = 0xcb |
{ | ||
"name": "msgpack5", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "A msgpack v5 implementation for node.js and the browser, with extension points", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -100,3 +100,3 @@ msgpack5 [![Build Status](https://travis-ci.org/mcollina/msgpack5.png)](https://travis-ci.org/mcollina/msgpack5) | ||
<a name="msgpack"></a> | ||
### msgpack() | ||
### msgpack(options(obj)) | ||
@@ -106,2 +106,6 @@ Creates a new instance on which you can register new types for being | ||
options: | ||
- `forceFloat64`, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults is false. | ||
------------------------------------------------------- | ||
@@ -108,0 +112,0 @@ <a name="encode"></a> |
@@ -24,2 +24,12 @@ | ||
t.test('forceFloat64 encoding ' + num, function(t) { | ||
var enc = msgpack({ forceFloat64: true }) | ||
, buf = enc.encode(num) | ||
, 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.end() | ||
}) | ||
t.test('decoding ' + num, function(t) { | ||
@@ -26,0 +36,0 @@ var buf = new Buffer(5) |
429262
8739
229