Esempio n. 1
0
    def consumer_consume16_1():
        data = b'\xa5\xa5'
        valid = [0xa5a5]

        bc = bitmap.consumer(data)
        res = []
        while len(res) < len(valid):
            res.append(bc.consume(16))

        if res == valid:
            raise Success
Esempio n. 2
0
    def consumer_consume8_1():
        data = b'\xa0'
        valid = [0xa0]

        bc = bitmap.consumer(data)
        res = []
        while len(res) < len(valid):
            res.append(bc.consume(8))

        if res == valid:
            raise Success
Esempio n. 3
0
    def consumer_consume1_8():
        data = b'\x80'
        valid = [1, 0, 0, 0, 0, 0, 0, 0]

        bc = bitmap.consumer(data)
        res = []
        while len(res) < len(valid):
            res.append(bc.consume(1))

        if res == valid:
            raise Success
Esempio n. 4
0
    def consumer_consumeiterable():
        data = bytes(bytearray([0xa5, 0xa5]))
        valid = [0xa, 0x5, 0xa, 0x5]

        bc = bitmap.consumer(data)
        res = []
        while len(res) < len(valid):
            item = bc.consume(4)
            res.append(item)

        if res == valid:
            raise Success
Esempio n. 5
0
    def consumer_consume4_4():
        data = b'\xa5\xa5'
        valid = [0xa, 0x5, 0xa, 0x5]

        bc = bitmap.consumer(data)
        res = []
        while len(res) < len(valid):
            item = bc.consume(4)
            res.append(item)

        if res == valid:
            raise Success
Esempio n. 6
0
def consume(iterable, bits=(32 - 6, )):
    source = bitmap.consumer(iterable)
    special = source.consume(6)

    result = []
    for b in bits:
        s = abs(b)

        sf, mask = 2**(s - 1), (2**(s - 1)) - 1
        x = source.consume(s)

        if b < 0:
            if x & sf:
                x = x & mask
                x *= -1
            else:
                x &= mask

        result.append(x)

    return special, tuple(result)
Esempio n. 7
0
def consume(iterable, bits=(32-6,)):
    source = bitmap.consumer(iterable)
    special = source.consume(6)

    result = []
    for b in bits:
        s = abs(b)

        sf,mask = 2**(s-1), (2**(s-1))-1
        x = source.consume(s)

        if b < 0:
            if x & sf:
                x = x & mask
                x *= -1
            else:
                x &= mask

        result.append(x)

    return special,tuple(result)
Esempio n. 8
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)))))
Esempio n. 9
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('\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))))