From 20913c5e0e8a4ba1cd020ece0f8766c6b7b146a9 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 21 Dec 2015 17:23:05 -0800 Subject: [PATCH] Add .pyc to gitignore; Fix js example --- .gitignore | 1 + example/js/wire.js | 8 +++----- example/python/tmsp/wire.py | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 381931381..d2d414be4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp *.swo +*.pyc diff --git a/example/js/wire.js b/example/js/wire.js index 13ee55292..42c308674 100644 --- a/example/js/wire.js +++ b/example/js/wire.js @@ -1,5 +1,3 @@ -math = require("math") - module.exports = { decode_string: decode_string, decode_varint: decode_varint, @@ -37,14 +35,14 @@ function encode_big_endian(i, size){ if (size == 0){ return new Buffer(0); } - b = encode_big_endian(math.floor(i/256), size-1); + b = encode_big_endian(Math.floor(i/256), size-1); return Buffer.concat([b, new Buffer([i%256])]); } function decode_big_endian(reader, size){ if (size == 0){ return 0 } firstByte = reader.read(1)[0]; - return firstByte*(math.pow(256, size-1)) + decode_big_endian(reader, size-1) + return firstByte*(Math.pow(256, size-1)) + decode_big_endian(reader, size-1) } function encode_string(s){ @@ -70,7 +68,7 @@ function encode_varint(i){ big_end = encode_big_endian(i, size); if (negate){ size += 0xF0 } - var buf = new Buffer([1]); + var buf = new Buffer([size]); return Buffer.concat([buf, big_end]) } diff --git a/example/python/tmsp/wire.py b/example/python/tmsp/wire.py index fde4e1605..1f16855a7 100644 --- a/example/python/tmsp/wire.py +++ b/example/python/tmsp/wire.py @@ -25,7 +25,7 @@ def uvarint_size(i): def encode_big_endian(i, size): if size == 0: return bytearray() - return encode_big_endian(i/256, size-1) + bytearray([i%256]) + return encode_big_endian(i/256, size-1) + bytearray([i%256]) def decode_big_endian(reader, size): if size == 0: @@ -36,14 +36,14 @@ def decode_big_endian(reader, size): # ints are max 16 bytes long def encode_varint(i): negate = False - if i < 0: + if i < 0: negate = True i = -i size = uvarint_size(i) if size == 0: return bytearray([0]) big_end = encode_big_endian(i, size) - if negate: + if negate: size += 0xF0 return bytearray([size]) + big_end @@ -57,7 +57,7 @@ def decode_varint(reader): if negate: size = size -0xF0 i = decode_big_endian(reader, size) if negate: i = i*(-1) - return i + return i def encode_string(s): size = encode_varint(len(s))