From 5c5762a0000c9f8d1684ca2ac09f0a69d3e2d7c9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 17 May 2014 09:50:45 -0500 Subject: [PATCH] framer: fix 32 and 64 bit support for varint(). Signed-off-by: Fedor Indutny --- lib/bcoin/protocol/framer.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/bcoin/protocol/framer.js b/lib/bcoin/protocol/framer.js index fb7b584c..6828f81f 100644 --- a/lib/bcoin/protocol/framer.js +++ b/lib/bcoin/protocol/framer.js @@ -105,14 +105,18 @@ function varint(arr, value, off) { arr[off + 2] = value >>> 8; return 3; } else if (value <= 0xffffffff) { - arr[off] = 0xfd; - arr[off + 3] = value & 0xff; - arr[off + 4] = (value >>> 8) & 0xff; - arr[off + 5] = (value >>> 16) & 0xff; - arr[off + 6] = value >>> 24; + arr[off] = 0xfe; + arr[off + 1] = value & 0xff; + arr[off + 2] = (value >>> 8) & 0xff; + arr[off + 3] = (value >>> 16) & 0xff; + arr[off + 4] = value >>> 24; return 5; + } else if (peers.length <= 0xffffffffffffffff) { + p[off] = 0xff; + utils.writeU64(arr, value, off + 1); + return 9; } else { - throw new Error('64bit varint not supported yet'); + throw new Error('>64bit varint not supported yet'); } }