当前位置: 首页>>代码示例>>Python>>正文


Python struct.iter_unpack函数代码示例

本文整理汇总了Python中struct.iter_unpack函数的典型用法代码示例。如果您正苦于以下问题:Python iter_unpack函数的具体用法?Python iter_unpack怎么用?Python iter_unpack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了iter_unpack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: extractFile

def extractFile(filename, start, end, palette, names):
    dims = []

    with open(filename, 'rb') as artFile:
        artFile.seek(16)

        count = end - start + 1
        widths = [x[0] for x in struct.iter_unpack('<H', artFile.read(count * 2))]
        if len(widths) < count:
            raise BadArtFileException("Couldn't read enough widths.")
        heights = [x[0] for x in struct.iter_unpack('<H', artFile.read(count * 2))]
        if len(heights) < count:
            raise BadArtFileException("Couldn't read enough heights.")
        dims = zip(widths, heights)

        #don't need the rest of this
        artFile.seek(count * 4, 1)

        for dim in enumerate(dims):
            width, height = dim[1]
            if width == 0 or height == 0:
                continue
            data = artFile.read(width * height)
            if len(data) < width * height:
                raise BadArtFileException("Not enough data.")
            data = rearrangeData(data, width, height)

            name = ""
            try:
                name = names[start + dim[0]]
            except KeyError:
                name = "TILE{:04d}".format(start + dim[0])

            print(" -> Writing out {:s}...".format(name))
            writeBMP(name, width, height, palette, data)
开发者ID:paulguy,项目名称:minitools,代码行数:35,代码来源:artex.py

示例2: readPlanes

def readPlanes(hdr, data):
    planedata = (x[0] for x in iter_unpack("24s", data[hdr.planeDataOffset:][:hdr.planeCount * 24]))
    normals   = (Point(*x) for x in iter_unpack("<3i", data[hdr.normalListOffset:][:hdr.planeCount * 24]))
    data = BytesIO(data[hdr.planeListOffset:])
    for plane, normal in zip(planedata, normals):
        planePointCount, unknown1, texture, unknown2 = unpack("<2BH6s", data.read(10))
        planePoints = [PlanePoint(int(point[0]/12), *point[1:])
            for point in iter_unpack("<IHH", data.read(planePointCount * 8))]
        yield Plane(unknown1, texture, unknown2, planePoints, normal, plane)
开发者ID:basecq,项目名称:battlespire-tools,代码行数:9,代码来源:3dtool.py

示例3: packets_from_file

def packets_from_file(filename, recording_time, chunksize=102):
    with open(filename, "rb") as f:
        while True:
            chunk = f.read(chunksize)
            if chunk:
                sensor_time = datetime.timedelta(milliseconds=struct.unpack("<I", chunk[:4])[0])  # ms since start of capturing system
                fused_time = recording_time + sensor_time
                packet = {
                    'timestamp': fused_time,
                    'data': {}
                }
                counter = 0
                for qw, qx, qy, qz, ax, ay, az in struct.iter_unpack("<hhhhhhh", chunk[4:]):
                    scale_q = (1.0 / (1 << 14))
                    scale_a = 1.0 / 100
                    packet['data'][sensor_id[counter]] = {
                        # Decode Quaternion: Orientation data (unit-less)
                        'orientation': [round(scale_q * qw, 6),
                                        round(scale_q * qx, 6),
                                        round(scale_q * qy, 6),
                                        round(scale_q * qz, 6)],
                        # Decode Vector: Acceleration data (m/s^2)
                        'acceleration': [round(scale_a * ax, 2),
                                         round(scale_a * ay, 2),
                                         round(scale_a * az, 2)]
                    }
                    counter += 1
                yield packet
            else:
                break
开发者ID:TomWieschalla,项目名称:Masterprojekt-WS15-16-MMI-IoT,代码行数:30,代码来源:generator.py

示例4: _decode_header

def _decode_header(status_dict, names_list, data):

    names_list = [name[0].split(b"\x00", 1)[0] for name in 
        struct.iter_unpack(f"{FGC_MAX_DEV_LEN + 1}s", 
                            data[0 : FGCD_MAX_DEVS * (FGC_MAX_DEV_LEN + 1)])]

    offset = FGCD_MAX_DEVS * (FGC_MAX_DEV_LEN + 1)

    (status_dict["hostname"], 
        status_dict["recv_time_sec"],
        status_dict["recv_time_usec"], 
        status_dict["id"],
        status_dict["sequence"],
        status_dict["send_time_sec"],
        status_dict["send_time_usec"],
        status_dict["time_sec"],
        status_dict["time_usec"]) = struct.unpack(f"!{HOST_NAME_MAX}sllllllll", 
                                                    data[offset:])

    status_dict["hostname"] = status_dict["hostname"].split(b"\x00", 1)[0].decode()

    if not status_dict["hostname"]:
        status_dict.clear()
        return None

    return status_dict, names_list
开发者ID:carlosghabrous,项目名称:ghabcode,代码行数:26,代码来源:pyfgc_statussrv.py

示例5: give_motion_frame

    def give_motion_frame(self):
        """Read the next sample from the POS file and assign to coil objects.
        :returns: error code, packed bytestring with dataframe response
        """
        if self.motion_lines_read < self.max_num_frames:

            measurements = self.file.read(self.bytes_in_frame)

            # there appears to be no timestamp in the data
            timestamp = MocapParent.timestamp_to_microsecs(self.motion_lines_read * self.frame_time)

            # 7I is integers for: x, y, z, phi, theta, rms, extra
            measurements_by_coil = struct.iter_unpack('< 7f', measurements[:])
            #print('&&&',measurements_by_coil)
            for coilvals, coilobj in zip(measurements_by_coil, self.component.coils):
                floatvals = MocapParent.make_float_or_zero(coilvals)
                coilobj.set_args_to_vars(floatvals, mapping=self.mappings)

            self.component.timestamp = timestamp
            self.latest_timestamp = timestamp
            print('test timestamp!!', self.latest_timestamp)

            self.motion_lines_read += 1
            return 3, DataFrame(components=[self.component]).pack_components_to_df(), None

        # no more data available (static, give up)
        else:
            print("All the frames have been read")
            return 4, "No more frames left in mocap file"
开发者ID:ahewer,项目名称:ematoblender,代码行数:29,代码来源:mocap_file_parser.py

示例6: parse_dict

def parse_dict(data):
    dct = {}
    mode = 'pad'
    key = []
    value = []

    for c in struct.iter_unpack('c', data):
        c = c[0]

        if mode == 'pad':
            if c in (bytes([0]), bytes([3])):
                continue
            else:
                mode = 'key'

        if mode == 'key':
            if c == bytes([0]):
                mode = 'value'
            else:
                key.append(c.decode())

        elif mode == 'value':
            if c == bytes([0]):
                dct[''.join(key)] = ''.join(value)
                key = []
                value = []
                mode = 'pad'
            else:
                value.append(c.decode())

    return dct
开发者ID:johnnykv,项目名称:heralding,代码行数:31,代码来源:postgresql.py

示例7: test_module_func

 def test_module_func(self):
     # Sanity check for the global struct.iter_unpack()
     it = struct.iter_unpack('>IB', bytes(range(1, 11)))
     self.assertEqual(next(it), (0x01020304, 5))
     self.assertEqual(next(it), (0x06070809, 10))
     self.assertRaises(StopIteration, next, it)
     self.assertRaises(StopIteration, next, it)
开发者ID:M31MOTH,项目名称:cpython,代码行数:7,代码来源:test_struct.py

示例8: parse_minor_mesh_form

    def parse_minor_mesh_form(self, mesh_form, lod_lev=0):

        if lod_lev not in self.lods:
            self.lods[lod_lev] = {}
            self.lods[lod_lev]["mats"] = []
            self.lods[lod_lev]["altmats"] = []
            self.lods[lod_lev]["lightflags"] = []

        vers_form = self.iff.read_data()
        mesh_vers = int(vers_form["name"].decode("ascii"))
        self.lods[lod_lev]["version"] = mesh_vers
        mnrmsh_read = 16  # Bytes for version form header

        while mnrmsh_read < mesh_form["length"]:
            mdat = self.iff.read_data()

            mnrmsh_read += 8 + mdat["length"]
            mnrmsh_read += 1 if mdat["length"] % 2 == 1 else 0

            if mdat["name"] == b"NAME":
                self.lods[lod_lev]["name"] = (
                    self.parse_cstr(mdat["data"], 0))
            elif mdat["name"] == b"FACE":

                # This isn't part of Wing Blender, so I'm using features
                # from newer versions of Python 3.
                for f in struct.iter_unpack(self.FACE_FMT, mdat["data"]):
                    if f[2] not in self.lods[lod_lev]["mats"]:
                        self.lods[lod_lev]["mats"].append(f[2])
                    if f[5] not in self.lods[lod_lev]["lightflags"]:
                        self.lods[lod_lev]["lightflags"].append(f[5])
                    if f[6] not in self.lods[lod_lev]["altmats"]:
                        self.lods[lod_lev]["altmats"].append(f[6])
开发者ID:Talon1024,项目名称:WCPBlenderExporter,代码行数:33,代码来源:query_mtls.py

示例9: parse_compact_node6_info

def parse_compact_node6_info(data):
    """
    Unpack a list of node id, IPv6 address and port returned by a find_node or get_peers request.
    """
    for frame in struct.iter_unpack("!20s8HH", data):
        # (id, (ipv6, port))
        yield {'id':frame[0], 'addr':('{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}'.format(*frame[1:9]), frame[9])}
开发者ID:agermann93,项目名称:pathspider,代码行数:7,代码来源:torrent.py

示例10: get_intlist

def get_intlist(elf):
    intdata = elf.get_section_by_name("intList").data()

    header_sz = struct.calcsize(intlist_header_fmt)
    header = struct.unpack_from(intlist_header_fmt, intdata, 0)
    intdata = intdata[header_sz:]

    spurious_code = header[0]
    spurious_nocode = header[1]

    debug("spurious handler (code)    : %s" % hex(header[0]))
    debug("spurious handler (no code) : %s" % hex(header[1]))

    intlist = [i for i in
            struct.iter_unpack(intlist_entry_fmt, intdata)]

    debug("Configured interrupt routing")
    debug("handler    irq pri vec dpl")
    debug("--------------------------")

    for irq in intlist:
        debug("{0:<10} {1:<3} {2:<3} {3:<3} {4:<2}".format(
            hex(irq[0]),
            "-" if irq[1] == -1 else irq[1],
            "-" if irq[2] == -1 else irq[2],
            "-" if irq[3] == -1 else irq[3],
            irq[4]))

    return (spurious_code, spurious_nocode, intlist)
开发者ID:rsalveti,项目名称:zephyr,代码行数:29,代码来源:gen_idt.py

示例11: decode_tilemap

def decode_tilemap(tilemap, tiles, palettes):
    """
    Creates a list of colored tiles from a tilemap, raw tiles and a
    color palette
    """
    tilemap_tiles = []

    for char in struct.iter_unpack("<H", tilemap):
        char = char[0]
        # Layout: Section 9.3 at http://www.coranac.com/tonc/text/regbg.htm
        tile_id = char & ((1 << 10) - 1)
        flip_h = bool(char & (1 << 10))
        flip_v = bool(char & (1 << 11))
        pal_id = char >> 12

        pal = palettes[pal_id]
        tile = color_tile(tiles[tile_id], pal)
        tile_img = tile_image(tile)
        if flip_h:
            tile_img = tile_img.transpose(Image.FLIP_LEFT_RIGHT)
        if flip_v:
            tile_img = tile_img.transpose(Image.FLIP_TOP_BOTTOM)

        tilemap_tiles.append(tile_img)

    return tilemap_tiles
开发者ID:Yepoleb,项目名称:TileCodecs,代码行数:26,代码来源:gba.py

示例12: parse_cmap

def parse_cmap(tree, node, data):
    i = -1
    for g, b, r in iter_unpack("3B", data):
        i += 1
        if r == g == b == 0:
            continue
        node.append(element("colour", text="%d %d %d" % (r, g, b), attrib={"id": str(i)}))
开发者ID:basecq,项目名称:battlespire-tools,代码行数:7,代码来源:bsitool.py

示例13: parse_6int32

def parse_6int32(name, node, data):
    node.data = [Point(*x) for x in iter_unpack("<3i", data)]
    for point in node.data:
        corner = element("corner")
        for k, v in zip(point._fields, point):
            corner.append(element(k, text=str(v)))
        node.append(corner)
开发者ID:basecq,项目名称:battlespire-tools,代码行数:7,代码来源:bs6tool.py

示例14: test_extract_palette

    def test_extract_palette(self):
        extracted = assets.files.backgrounds['mindscape'].extract_palette()

        with open(os.path.join(test_dir, 'mindscap_palette_extract_1.bin'), 'rb') as f:
            test_data = f.read()

        assert extracted == [i[0] for i in iter_unpack('<H', test_data)]
开发者ID:joetsoi,项目名称:moonstone,代码行数:7,代码来源:test_piv.py

示例15: parse_compact_node_info

def parse_compact_node_info(data):
    """
    Unpack a list of node id, IPv4 address and port returned by a find_node or get_peers request.
    """
    for frame in struct.iter_unpack("!20s4BH", data):
        # (id, (ip, port))
        yield {'id':frame[0], 'addr':("{}.{}.{}.{}".format(frame[1], frame[2], frame[3], frame[4]), frame[5])}
开发者ID:agermann93,项目名称:pathspider,代码行数:7,代码来源:torrent.py


注:本文中的struct.iter_unpack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。