def str(self): data = map(ord, self.serialize()) res = [data[0] / 40, data.pop(0) % 40] data = iter(data) for n in data: v = bitmap.new(0, 0) while n & 0x80: v = bitmap.push(v, (n & 0x7f, 7)) n = data.next() v = bitmap.push(v, (n, 7)) res.append(bitmap.number(v)) return '.'.join(map(str, res))
def test_tag(): res = bitmap.new(0x1e, 5) res = bitmap.zero res = bitmap.push(res, (0x1f, 5)) res = bitmap.push(res, (0x1, 1)) res = bitmap.push(res, (0x10, 7)) res = bitmap.push(res, (0x1, 0)) res = bitmap.push(res, (0x0, 7)) x = pbinary.new(ber.Tag, source=ptypes.prov.string(bitmap.data(res))) print x.l print x['TagLong'][0] print x.int() print int(x['TagLong'])
def test_length(): res = bitmap.zero res = bitmap.push(res, (0, 1)) res = bitmap.push(res, (38, 7)) x = pbinary.new(ber.Length,source=ptypes.prov.string(bitmap.data(res))) print(x.l) print(x.int()) res = bitmap.zero res = bitmap.push(res, (0x81,8)) res = bitmap.push(res, (0xc9,8)) x = pbinary.new(ber.Length,source=ptypes.prov.string(bitmap.data(res))) print(x.l) print(x.int())
def str(self): data = bytearray(self.serialize()) if len(data) > 0: res = [data[0] // 40, data.pop(0) % 40] data = iter(data) for n in data: val = bitmap.new(0,0) while n & 0x80: val = bitmap.push(val, (n & 0x7f, 7)) n = next(data) val = bitmap.push(val, (n, 7)) res.append(bitmap.int(val)) return '.'.join(map("{:d}".format, res)) return '0'
def set_bitmap_unsigned(): x = bitmap.new(0xf000000000000000, 64) #x = bitmap.set(x, 60, count=4) print(bitmap.string(x)) y, res = bitmap.shift(x, 4) print(res, bitmap.string(y)) x = bitmap.new(0, 0) x = bitmap.push(x, (0x1, 4)) x = bitmap.push(x, (0x2, 4)) x = bitmap.push(x, (0x3, 4)) x = bitmap.push(x, (0x4, 4)) print(x, bitmap.string(x)) x = bitmap.new(0, 0) x = bitmap.insert(x, (0x1, 4)) x = bitmap.insert(x, (0x2, 4)) x = bitmap.insert(x, (0x3, 4)) x = bitmap.insert(x, (0x4, 4)) print(x, bitmap.string(x)) x = bitmap.consumer(b'\x12\x34') print(x.consume(4)) print(x.consume(4)) print(x.consume(4)) print(x.consume(4)) x = bitmap.new(0, 4) for i in range(6): print(x) x = bitmap.add(x, 3) for i in range(6): print(x) x = bitmap.sub(x, 6) x = bitmap.new(4, 4) print(bitmap.string(bitmap.ror(bitmap.ror(bitmap.ror(x)))))
def set_bitmap_unsigned(): x = bitmap.new(0xf000000000000000,64) #x = bitmap.set(x, 60, count=4) print bitmap.string(x) y,res = bitmap.shift(x, 4) print res,bitmap.string(y) x = bitmap.new(0,0) x = bitmap.push(x, (0x1,4) ) x = bitmap.push(x, (0x2,4) ) x = bitmap.push(x, (0x3,4) ) x = bitmap.push(x, (0x4,4) ) print x,bitmap.string(x) x = bitmap.new(0,0) x = bitmap.insert(x, (0x1,4) ) x = bitmap.insert(x, (0x2,4) ) x = bitmap.insert(x, (0x3,4) ) x = bitmap.insert(x, (0x4,4) ) print x,bitmap.string(x) x = bitmap.consumer('\x12\x34') print x.consume(4) print x.consume(4) print x.consume(4) print x.consume(4) x = bitmap.new(0, 4) for i in six.moves.range(6): print x x = bitmap.add(x, 3) for i in six.moves.range(6): print x x = bitmap.sub(x, 6) x = bitmap.new(4,4) print bitmap.string(bitmap.ror(bitmap.ror(bitmap.ror(x))))
def push_bitmap_signed(): x = (15, -4) res = bitmap.push(x, (15, 4)) if res == (0xff, -8) and bitmap.value(res) == -1: raise Success
def push_bitmap_unsigned(): x = (15, 4) res = bitmap.push(x, (15, 4)) if res == (0xff, 8) and bitmap.value(res) == 255: raise Success
def push_bitmap_signed(): x = (15,-4) res = bitmap.push(x, (15,4)) if res == (0xff,-8) and bitmap.value(res) == -1: raise Success
def push_bitmap_unsigned(): x = (15,4) res = bitmap.push(x, (15,4)) if res == (0xff,8) and bitmap.value(res) == 255: raise Success