From 1b5df81b36227352679c010886344bfba31342d8 Mon Sep 17 00:00:00 2001 From: ericz Date: Sat, 5 Jan 2013 23:04:26 -0800 Subject: [PATCH 1/4] properly detect utf8 str len --- lib/binarypack.js | 2 +- lib/bufferbuilder.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/binarypack.js b/lib/binarypack.js index 91a7a3f..208545b 100644 --- a/lib/binarypack.js +++ b/lib/binarypack.js @@ -212,7 +212,7 @@ BinaryPack.Packer.prototype.pack_bin = function(blob){ } BinaryPack.Packer.prototype.pack_string = function(str){ - var length = str.length; + var length = Buffer.byteLength(str); if (length <= 0x0f){ this.bufferBuilder.append(0xb0 + length, 2); } else if (length <= 0xffff){ diff --git a/lib/bufferbuilder.js b/lib/bufferbuilder.js index a0bd8d4..c964275 100644 --- a/lib/bufferbuilder.js +++ b/lib/bufferbuilder.js @@ -21,13 +21,16 @@ BufferBuilder.prototype.append = function(data, type) { // 7: Int32 // 8: Float // 9: Double - - if(type < 2) { - this._length += data.length; - } else { - this._length += this._sizes[type]; - } - + switch(type) { + case 0: + this._length += Buffer.byteLength(data); + break; + case 1: + this._length += data.length; + break; + default: + this._length += this._sizes[type]; + }; this._pieces.push([data, type]); }; From 793d93af3ffc829a20edf44cf056a5ce819aae54 Mon Sep 17 00:00:00 2001 From: ericz Date: Sat, 5 Jan 2013 23:05:08 -0800 Subject: [PATCH 2/4] 0.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d429bd..a28c07f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "binarypack", "description": "BinaryPack is a JSON-like binary serialization format", - "version": "0.0.2", + "version": "0.0.3", "homepage": "https://github.com/binaryjs/node-binarypack", "author": "Eric Zhang", "repository": { From 7bef3f4026a542fbdf2ab3c1ef24fe0893deb654 Mon Sep 17 00:00:00 2001 From: ericz Date: Tue, 2 Apr 2013 21:42:16 -0700 Subject: [PATCH 3/4] writeInt8BE -> writeInt8 --- lib/bufferbuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bufferbuilder.js b/lib/bufferbuilder.js index c964275..dd8bb0c 100644 --- a/lib/bufferbuilder.js +++ b/lib/bufferbuilder.js @@ -58,7 +58,7 @@ BufferBuilder.prototype.getBuffer = function() { cursor.writeUInt32BE(tuple[0]); break; case 5: - cursor.writeInt8BE(tuple[0]); + cursor.writeInt8(tuple[0]); break; case 6: cursor.writeInt16BE(tuple[0]); From cdc64bbc72547ed38e98f285e0808cd819581851 Mon Sep 17 00:00:00 2001 From: ericz Date: Tue, 2 Apr 2013 21:43:17 -0700 Subject: [PATCH 4/4] update to 0.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a28c07f..29869d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "binarypack", "description": "BinaryPack is a JSON-like binary serialization format", - "version": "0.0.3", + "version": "0.0.4", "homepage": "https://github.com/binaryjs/node-binarypack", "author": "Eric Zhang", "repository": {