예제 #1
0
def read_gints(dbfile, n):
    """Read N integers from the bytes stream dbfile. Expects that the file
    starts at a key byte.
    """

    count = 0
    read = dbfile.read
    for _ in xrange(n):
        if count == 0:
            key = ord(dbfile.read(1))
        code = key >> (count * 2) & 3
        if code == 0:
            yield ord(read(1))
        elif code == 1:
            yield unpack_ushort_le(read(2))[0]
        elif code == 2:
            yield unpack_uint_le(read(3) + "\x00")[0]
        else:
            yield unpack_uint_le(read(4))[0]

        count = (count + 1) % 4
예제 #2
0
def read_gints(dbfile, n):
    """Read N integers from the bytes stream dbfile. Expects that the file
    starts at a key byte.
    """

    count = 0
    read = dbfile.read
    for _ in xrange(n):
        if count == 0:
            key = ord(dbfile.read(1))
        code = key >> (count * 2) & 3
        if code == 0:
            yield ord(read(1))
        elif code == 1:
            yield unpack_ushort_le(read(2))[0]
        elif code == 2:
            yield unpack_uint_le(read(3) + "\x00")[0]
        else:
            yield unpack_uint_le(read(4))[0]

        count = (count + 1) % 4
예제 #3
0
 def read_ushort_le(self):
     return unpack_ushort_le(self.read(_SHORT_SIZE))[0]
예제 #4
0
 def read_ushort_le(self):
     return unpack_ushort_le(self.read(_SHORT_SIZE))[0]