Browse Source

Add .pyc to gitignore; Fix js example

pull/1780/head
Jae Kwon 9 years ago
parent
commit
20913c5e0e
3 changed files with 8 additions and 9 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -5
      example/js/wire.js
  3. +4
    -4
      example/python/tmsp/wire.py

+ 1
- 0
.gitignore View File

@ -1,2 +1,3 @@
*.swp
*.swo
*.pyc

+ 3
- 5
example/js/wire.js View File

@ -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])
}


+ 4
- 4
example/python/tmsp/wire.py View File

@ -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))


Loading…
Cancel
Save