• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python struct.unpack_from函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _get_udp_connection

    def _get_udp_connection(self, host, port):
        # build connection request payload
        transaction_id = int(randrange(0, 255))
        buff = struct.pack('!q', CONNECTION_ID)
        buff += struct.pack('!i', ACTION_CONNECT)
        buff += struct.pack('!i', transaction_id)

        # send payload and get response
        self._socket.sendto(buff, (host, port))
        try:
            response = self._socket.recv(2048)
        except socket.timeout:
            # TODO: issue warning here
            print "tracker down: %s" % host
            return None
        if len(response) < 16:
            # TODO: issue warning here
            print "wrong response length"
            return None

        # extract response information
        resp_action, resp_transaction_id = struct.unpack_from('!ii', response, 0)
        if transaction_id != resp_transaction_id:
            # TODO: issue warning instead
            raise ValueError('Transaction IDs do not match (req=%d resp=%d)' % (transaction_id, resp_transaction_id))
        if resp_action == ACTION_ERROR:
            error = struct.unpack_from('!s', response, 8)[0]
            # TODO: issue warning instead
            raise RuntimeError('Unable to setup a connection: %s' % error)

        elif resp_action == ACTION_CONNECT:
            connection_id = struct.unpack_from('!q', response, 8)[0]
            return connection_id
        return None
开发者ID:carriercomm,项目名称:TorrentInfo,代码行数:34,代码来源:info.py


示例2: _parse_hpr_time_series

    def _parse_hpr_time_series(self, offset, rules):
        """
        Convert the binary data into particle data for the Heading, Pitch, Time Series Data Type
        """
        # Unpack the unpacking rules
        (hpr_num_name, beam_angle_name, spare_name, hpr_time_names),\
        (hpr_num_fmt, beam_angle_fmt, spare_fmt, hpr_time_fmt) = zip(*rules)

        # First unpack the array length and single length value, no need to unpack spare
        (hpr_num_data, beam_angle_data) = struct.unpack_from(
            '<%s%s' % (hpr_num_fmt, beam_angle_fmt), self.raw_data, offset)

        # Then unpack the array using the retrieved lengths value
        next_offset = offset + struct.calcsize(hpr_num_fmt) + struct.calcsize(beam_angle_fmt) + \
                      struct.calcsize(spare_fmt)
        hpr_time_list_data = struct.unpack_from(
            '<%s%s' % (hpr_num_data * HPR_TIME_SERIES_ARRAY_SIZE, hpr_time_fmt), self.raw_data, next_offset)

        # convert to numpy array and reshape the data to a 2d array per IDD spec
        transformed_hpr_time_data = numpy.array(hpr_time_list_data).reshape(
            (hpr_num_data, HPR_TIME_SERIES_ARRAY_SIZE)).transpose().tolist()

        # Add to the collected parameter data
        self.final_result.extend(
            ({DataParticleKey.VALUE_ID: hpr_num_name, DataParticleKey.VALUE: hpr_num_data},
             {DataParticleKey.VALUE_ID: beam_angle_name, DataParticleKey.VALUE: beam_angle_data},
             {DataParticleKey.VALUE_ID: hpr_time_names[HEADING_TIME_SERIES_IDX],
              DataParticleKey.VALUE: transformed_hpr_time_data[HEADING_TIME_SERIES_IDX]},
             {DataParticleKey.VALUE_ID: hpr_time_names[PITCH_TIME_SERIES_IDX],
              DataParticleKey.VALUE: transformed_hpr_time_data[PITCH_TIME_SERIES_IDX]},
             {DataParticleKey.VALUE_ID: hpr_time_names[ROLL_TIME_SERIES_IDX],
              DataParticleKey.VALUE: transformed_hpr_time_data[ROLL_TIME_SERIES_IDX]}))
开发者ID:mcworden,项目名称:mi-dataset-1,代码行数:32,代码来源:adcpt_m_wvs.py


示例3: unpack

    def unpack(self, info):
        self._tag, = unpack_from('>c', info)
        skip = 1

        if self._tag in b'BCDFIJSZs':
            self._value, = unpack_from('>H', info[skip:])
            skip += 2
        elif self._tag == b'e':
            self._value = unpack_from('>HH', info[skip:])
            skip += 4
        elif self._tag == b'c':
            self._value, = unpack_from('>H', info[skip:])
            skip += 2
        elif self._tag == b'@':
            annotation = RuntimeVisibleAnnotation(self._cf)
            skip += annotation.unpack(info[skip:])
            self._value = annotation
        elif self._tag == b'[':
            num_values, = unpack_from('>H', info[skip:])
            skip += 2
            values = []
            for n in range(num_values):
                value = ElementValue(self._cf)
                skip += value.unpack(info[skip:])
                values.append(value)
            self._value = values
        else:
            raise ValueError("Unknown ElementValue tag {}".format(self._tag))

        return skip
开发者ID:lukegb,项目名称:Jawa,代码行数:30,代码来源:annotations.py


示例4: script_GetOp

def script_GetOp(bytes):
    i = 0
    while i < len(bytes):
        vch = None
        opcode = ord(bytes[i])
        i += 1
        if opcode >= opcodes.OP_SINGLEBYTE_END:
            opcode <<= 8
            opcode |= ord(bytes[i])
            i += 1

        if opcode <= opcodes.OP_PUSHDATA4:
            nSize = opcode
            if opcode == opcodes.OP_PUSHDATA1:
                nSize = ord(bytes[i])
                i += 1
            elif opcode == opcodes.OP_PUSHDATA2:
                (nSize,) = struct.unpack_from('<H', bytes, i)
                i += 2
            elif opcode == opcodes.OP_PUSHDATA4:
                (nSize,) = struct.unpack_from('<I', bytes, i)
                i += 4
            vch = bytes[i:i+nSize]
            i += nSize

        yield (opcode, vch, i)
开发者ID:Roverok,项目名称:electrum-server,代码行数:26,代码来源:deserialize.py


示例5: Run

  def Run(self, args):
    """Run."""
    # This action might crash the box so we need to flush the transaction log.
    self.SyncTransactionLog()

    # Do any initialization we need to do.
    logging.debug("Querying device %s", args.path)

    fd = win32file.CreateFile(
        args.path,
        win32file.GENERIC_READ | win32file.GENERIC_WRITE,
        win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
        None,
        win32file.OPEN_EXISTING,
        win32file.FILE_ATTRIBUTE_NORMAL,
        None)

    data = win32file.DeviceIoControl(fd, INFO_IOCTRL, "", 1024, None)
    fmt_string = "QQl"
    cr3, _, number_of_runs = struct.unpack_from(fmt_string, data)

    result = rdfvalue.MemoryInformation(
        cr3=cr3,
        device=rdfvalue.PathSpec(
            path=args.path,
            pathtype=rdfvalue.PathSpec.PathType.MEMORY))

    offset = struct.calcsize(fmt_string)
    for x in range(number_of_runs):
      start, length = struct.unpack_from("QQ", data, x * 16 + offset)
      result.runs.Append(offset=start, length=length)

    self.SendReply(result)
开发者ID:kartikeyap,项目名称:grr,代码行数:33,代码来源:windows.py


示例6: load_label_data_set

    def load_label_data_set(self, label_data_dir):
        logging.info("load label set from {0}.".format(label_data_dir))

        with open(label_data_dir, "rb") as binary_file_handle:
            label_data_buffer = binary_file_handle.read()

        head = struct.unpack_from('>II' , label_data_buffer ,0)
        logging.info("head:{0}".format(head))

        label_num = head[1]
        logging.info("img_num:{0}".format(label_num))

        offset = struct.calcsize('>II')
        logging.info("offset:{0}".format(offset))

        img_num_string='>'+str(label_num)+"B"
        logging.info("img_num_string:{0}".format(img_num_string))

        all_label_2d_ndarray = struct.unpack_from(img_num_string, label_data_buffer, offset)
        all_label_2d_ndarray = np.reshape(all_label_2d_ndarray, [label_num, 1])
        logging.info("len(all_label_2d_ndarray):{0}".format(len(all_label_2d_ndarray)))
        logging.info("type(all_label_2d_ndarray):{0}".format(type(all_label_2d_ndarray)))

        logging.info("all_label_2d_ndarray[0]:{0}".format(all_label_2d_ndarray[0]))
        logging.info("type(all_label_2d_ndarray[0]):{0}".format(type(all_label_2d_ndarray[0])))

        logging.info("all_label_2d_ndarray[0][0]:{0}".format(all_label_2d_ndarray[0][0]))
        logging.info("type(all_label_2d_ndarray[0][0]):{0}".format(type(all_label_2d_ndarray[0][0])))

        logging.info("Load label finished.")
        return all_label_2d_ndarray
开发者ID:ysh329,项目名称:my-first-cnn,代码行数:31,代码来源:class_read_raw_data.py


示例7: __init__

 def __init__(self, idx, buf):
     self.inode_no = idx
     sb = buffer(bytearray(buf))
     sz = 0
     fmt = "<2H5I2H3I"
     (self.i_mode,
      self.i_uid,
      self.i_size,
      self.i_atime,
      self.i_ctime,
      self.i_mtime,
      self.i_dtime,
      self.i_gid,
      self.i_links_count,
      self.i_blocks,
      self.i_flags,
      self.i_osd1) = struct.unpack_from(fmt, sb, sz)
     sz += struct.calcsize(fmt)
     fmt = "<15I"
     self.i_block = struct.unpack_from(fmt, sb, sz)
     sz += struct.calcsize(fmt)
     fmt = "<4I12s"
     (self.i_gneration,
      self.i_file_acl,
      self.i_dir_acl,
      self.i_faddr,
      self.i_osd2) = struct.unpack_from(fmt, sb, sz)
开发者ID:leyyer,项目名称:exfsh,代码行数:27,代码来源:extfs.py


示例8: __init__

 def __init__(self, data):
     self.ident = data[:4]
     self.record_size, self.type, self.count, self.encoding = unpack_from(b'>IHHI', data, 4)
     self.encoding = {
             1252 : 'cp1252',
             65001: 'utf-8',
         }.get(self.encoding, repr(self.encoding))
     rest = list(unpack_from(b'>IIIIIIII', data, 16))
     self.num_of_resource_records = rest[2]
     self.num_of_non_dummy_resource_records = rest[3]
     self.offset_to_href_record = rest[4]
     self.unknowns1 = rest[:2]
     self.unknowns2 = rest[5]
     self.header_length = rest[6]
     self.title_length = rest[7]
     self.resources = []
     self.hrefs = []
     if data[48:52] == b'EXTH':
         self.exth = EXTHHeader(data[48:])
         self.title = data[48 + self.exth.length:][:self.title_length].decode(self.encoding)
         self.is_image_container = self.exth[539] == 'application/image'
     else:
         self.exth = ' No EXTH header present '
         self.title = ''
         self.is_image_container = False
     self.bytes_after_exth = data[self.header_length + self.title_length:]
     self.null_bytes_after_exth = len(self.bytes_after_exth) - len(self.bytes_after_exth.replace(b'\0', b''))
开发者ID:j-howell,项目名称:calibre,代码行数:27,代码来源:containers.py


示例9: script_GetOp

def script_GetOp(bytes):
    i = 0
    while i < len(bytes):
        vch = None
        opcode = ord(bytes[i])
        i += 1

        if opcode <= opcodes.OP_PUSHDATA4:
            nSize = opcode
            if opcode == opcodes.OP_PUSHDATA1:
                nSize = ord(bytes[i])
                i += 1
            elif opcode == opcodes.OP_PUSHDATA2:
                (nSize,) = struct.unpack_from('<H', bytes, i)
                i += 2
            elif opcode == opcodes.OP_PUSHDATA4:
                (nSize,) = struct.unpack_from('<I', bytes, i)
                i += 4
            if i+nSize > len(bytes):
              vch = "_INVALID_"+bytes[i:]
              i = len(bytes)
            else:
             vch = bytes[i:i+nSize]
             i += nSize

        yield (opcode, vch, i)
开发者ID:santzi,项目名称:electrum-nmc-server,代码行数:26,代码来源:deserialize.py


示例10: ReadRecord

def ReadRecord(d, offset=0x0):
    id = d[0]
    d=d[1:] # Eat id
    if id == 0xff or id == 0x4: # Normal end of Data
        return id, None, None
    sztotal = 1 
    assert RecPack.has_key(id), "Unknown record ID %i at offset %i" % (id, offset)
    if RecRepeat.has_key(id):
        sz = struct.calcsize(RecPack[id])
        init=struct.unpack_from(RecRepeat[id][1], d)
        szinit=struct.calcsize(RecRepeat[id][1])
        d=d[szinit:]
        sztotal += szinit
        res=[]
        for i in range(0, RecRepeat[id][0]):
            res.append(struct.unpack_from(RecPack[id], d))
            d=d[sz:]
            sztotal += sz
    elif type(RecPack[id]) == str:
        sz = struct.calcsize(RecPack[id])
        res = struct.unpack_from(RecPack[id], d)
        sztotal += sz
    elif type(RecPack[id]) == int: # 12-bit field array
        # A padding byte 0xFF may be present
        sz = RecPack[id] - 1
        res = ReadPacked12Bit(d[:sz])
        sztotal += sz
    return id, sztotal, res
开发者ID:greenthrall,项目名称:BB_Sync_Test,代码行数:28,代码来源:BodyBugg.py


示例11: _read_tag_data_info

def _read_tag_data_info(dmfile):
    tag_array_length = struct.unpack_from('>Q', dmfile.read(8))[0] #DM4 specifies this property as always big endian
    format_str = '>' + tag_array_length * 'q' #Big endian signed long
     
    tag_array_types = struct.unpack_from(format_str, dmfile.read(8*tag_array_length))
    
    return (tag_array_length,  tag_array_types)
开发者ID:dansteingart,项目名称:dm4reader,代码行数:7,代码来源:__init__.py


示例12: parseString

def parseString(db, offset):
    existence = unpack_from('b', db, offset)[0]
    if existence == 0x00:
        return ("", offset+1)
    elif existence == 0x0b:
        # decode ULEB128
        length = 0
        shift = 0
        offset += 1
        while True:
            val = unpack_from('B', db, offset)[0]
            length |= ((val & 0x7F) << shift)
            offset += 1
            if (val & (1 << 7)) == 0:
                break
            shift += 7

        string = unpack_from(str(length)+'s', db, offset)[0]
        offset += length

        unic = u''
        try:
            unic = unicode(string, 'utf-8')
        except UnicodeDecodeError:
            print "Could not parse UTF-8 string, returning empty string."

        return (unic, offset)
开发者ID:chudooder,项目名称:osutools,代码行数:27,代码来源:dbparse.py


示例13: sec_info

 def sec_info(self, secnum):
     start_offset, flgval = struct.unpack_from('>2L', self.datain, 78+(secnum*8))
     if secnum == self.num_sections:
         next_offset = len(self.datain)
     else:
         next_offset, nflgval = struct.unpack_from('>2L', self.datain, 78+((secnum+1)*8))
     return start_offset, flgval, next_offset
开发者ID:fireinice,项目名称:yakindlestrip,代码行数:7,代码来源:kindlestrip.py


示例14: parse_resp

    def parse_resp(self,buf):

        header_offset = 2
        avp_offset = 8
        nr = 0
        ns = 0

        # read the header
        (cflag,) = struct.unpack_from('!H', buf)

        cflag_bin = int2bin(cflag,16)
        ptype = cflag_bin[0]
        blen = cflag_bin[1]
        sbit = cflag_bin[4]
        obit = cflag_bin[6]
        pbit = cflag_bin[7]
        ver  = cflag_bin[12:16]

        if self.debug:
            print "<- l2tp packet dump"
            print "<-: l2tp cflag bits : %s|%s|%s|%s|%s|%s" % (ptype, blen, sbit, obit, pbit, ver)

        if ver != '0010': #
            print '!! Not an valid l2tp packet : discarding'
            return None

        if blen == '1':
            (plen,) = struct.unpack_from('!H', buf, offset=header_offset)
            if self.debug:
                print "<-: l2tp length : %d" % plen
            header_offset += 2

        (tid, sid) = struct.unpack_from('!HH', buf, offset=header_offset)
        if self.debug:
            print "<-: l2tp tunnel_id : %d, session_id : %d" % (tid, sid)
        header_offset += 4

        if sbit == '1':
            (ns, nr) = struct.unpack_from('!HH', buf, offset=header_offset)
            if self.debug:
                print "<-: l2tp ns : %d, nr : %d" % (ns, nr)
            header_offset += 4
            avp_offset += 4

        if obit == '1':
            (offset_size, offset_pad) = struct.unpack_from('!HH', buf, offset=header_offset)
            if self.debug:
                print "<-: l2tp offset_size : %d, offset_pad : %d" % (offset_size, offset_pad)
            header_offset += 4
            avp_offset += 4

        if ptype == '0': # data packet
            # write to pppd
            data = buf[header_offset:]
            try:
                async_buf = self.pppd_sync_to_async(data)
                pty._writen(self.pppd_fd, async_buf)
            except OSError, se:
                if se.args[0] not in (errno.EAGAIN, errno.EINTR):
                    raise
开发者ID:ut0mt8,项目名称:l2tpclient,代码行数:60,代码来源:l2tpclient.py


示例15: _tag_aux

def _tag_aux(fp, tb):
    bytes_read = 1
    tag = tb & CBOR_TYPE_MASK
    tag_aux = tb & CBOR_INFO_BITS
    if tag_aux <= 23:
        aux = tag_aux
    elif tag_aux == CBOR_UINT8_FOLLOWS:
        data = fp.read(1)
        aux = struct.unpack_from("!B", data, 0)[0]
        bytes_read += 1
    elif tag_aux == CBOR_UINT16_FOLLOWS:
        data = fp.read(2)
        aux = struct.unpack_from("!H", data, 0)[0]
        bytes_read += 2
    elif tag_aux == CBOR_UINT32_FOLLOWS:
        data = fp.read(4)
        aux = struct.unpack_from("!I", data, 0)[0]
        bytes_read += 4
    elif tag_aux == CBOR_UINT64_FOLLOWS:
        data = fp.read(8)
        aux = struct.unpack_from("!Q", data, 0)[0]
        bytes_read += 8
    else:
        assert tag_aux == CBOR_VAR_FOLLOWS, "bogus tag {0:02x}".format(tb)
        aux = None

    return tag, tag_aux, aux, bytes_read
开发者ID:DisposaBoy,项目名称:GoSublime,代码行数:27,代码来源:cbor.py


示例16: load_mnist

def load_mnist(im_path, lb_path):
	# loading images
	binfile = open(im_path, 'rb')
	buf = binfile.read()
	index = 0
	magic,numImages,numRows,numColumns = \
		struct.unpack_from('>IIII' , buf , index)
	index += struct.calcsize('>IIII')
	if magic!=2051:
		raise NameError('MNIST TRAIN-IMAGE INCCORECT!')
	ims = np.zeros([numImages, numRows*numColumns])
	for i in range(numImages):
		ims[i,:] = struct.unpack_from('>784B', buf, index)
		index += struct.calcsize('>784B');
	# loading labels
	binfile = open(lb_path, 'rb')
	buf = binfile.read()
	index = 0
	magic,numLabels = struct.unpack_from(
		'>II', 
		buf, 
		index
	)
	index += struct.calcsize('>II')
	if magic!=2049:
		raise NameError('MNIST TRAIN-LABEL INCORRECT!')
	lbs = np.zeros(numLabels)
	lbs[:] = struct.unpack_from(
		'>'+ str(numLabels) +'B', 
		buf, 
		index
	)
	return [ims, numRows, numColumns, lbs]
开发者ID:xiangchao027,项目名称:hybrid-learning-neural-network,代码行数:33,代码来源:main.py


示例17: load_image_data_set

    def load_image_data_set(self, img_data_dir):
        logging.info("Load image data set from {0}.".format(img_data_dir))


        with open(img_data_dir, "rb") as binary_file_handle:
            image_data_buffer = binary_file_handle.read()

        # '>IIII'是说使用大端法读取4个unsigned int32
        # unpack_from(...)
        # Unpack the buffer, containing packed C structure data, according to
        # fmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).
        head = struct.unpack_from('>IIII' , image_data_buffer ,0)
        logging.info("head:{0}".format(head))

        magic_num = struct.calcsize('>IIII')
        img_num = head[1]
        img_width = head[2]
        img_height = head[3]
        logging.info("magic_num:{0}".format(magic_num))
        logging.info("img_num:{0}".format(img_num))
        logging.info("img_width:{0}".format(img_width))
        logging.info("img_height:{0}".format(img_height))

        #[60000]*28*28
        all_img_bit = img_num * img_width * img_height
        all_img_bit_string = '>' + str(all_img_bit) + 'B' #like '>47040000B'
        logging.info("all_img_bit_string:{0}".format(all_img_bit_string))

        all_image_2d_ndarray = struct.unpack_from(all_img_bit_string, image_data_buffer, magic_num)
        all_image_2d_ndarray = np.reshape(all_image_2d_ndarray, [img_num, img_width, img_height])
        return all_image_2d_ndarray
开发者ID:ysh329,项目名称:my-first-cnn,代码行数:31,代码来源:class_read_raw_data.py


示例18: receptionListUser

 def receptionListUser(self,packet,status):
     self.listUser=[]
     lengthMsg=struct.unpack_from(">LH",packet)[1]
     print "00000000000000000000on reçoit la list0000000000000000000"
     lengthData=lengthMsg-8
     offset=8
     i=0
     while i< lengthData:
         lengthNameUser_Dispo=struct.unpack_from(">B",packet,offset)[0]
         lengthNameUser=lengthNameUser_Dispo>>1
         S=lengthNameUser_Dispo&1
         Data=">BH"+ str(lengthNameUser) + "s"
         userName= struct.unpack_from(Data,packet,offset)[2]
         userId=struct.unpack_from(Data,packet,offset)[1]
         if (S==1):
             ROOM=ROOM_IDS.MAIN_ROOM
         else:
             ROOM=ROOM_IDS.MOVIE_ROOM
         self.listUser.append((userName,ROOM))
         self.listUser_Id.append((userName,userId))
         i+=(lengthNameUser+3)
         offset+=(lengthNameUser+3)
     liste=[]
     if status==userStatus['waitingMainRoomUserList'] or status==userStatus['mainRoom']:
         liste=self.listUser
     elif status==userStatus['waitingfMovieRoomUserList'] or status==userStatus['movieRoom']:
         print "******************on entre dans cette boucle************************"
         i=0
         while i<len(self.listUser):
             liste.append((self.listUser[i][0],self.RoomName)) # il y'avait self.thisRoomName???
             i+=1
     if status==userStatus['mainRoom'] or status==userStatus['movieRoom']:
             self.clientProxy.setUserListONE(liste)
             print "§!§§§§§§§§§§§§§§§update ok "
开发者ID:delco225,项目名称:C2W,代码行数:34,代码来源:tcp_chat_client.py


示例19: __read_block15

 def __read_block15(self, size):
     low = self.blksize * ((self.blksize / 4) ** 2) + self.blksize * 12
     blk = []
     ndx = self.blksize / 4
     if self._cur_pos >= low:
         if self.inode.i_block[14] == 0:
             return blk
         cpos = self._cur_pos - low
         n3 = cpos / self.blksize
         r = cpos % self.blksize
         n2 = n3 / ndx
         n1 = n2 / ndx
         n0 = n1 / ndx
         fmt = "<%dI" % ndx
         b15 = struct.unpack_from(fmt, buffer(bytearray(self.filesys.read_block(self.inode.i_block[14]))))
         for x in b15[n0:]:
             assert(x > 0)
             c15 = struct.unpack_from(fmt, buffer(bytearray(self.filesys.read_block(x))))
             for y in c15[n1:]:
                 d15 = struct.unpack_from(fmt, buffer(bytearray(self.filesys.read_block(y))))
                 bk = self._do_read(d15[n2:], r, size)
                 r = 0
                 n2 = 0
                 blk += bk
                 size -= len(bk)
                 if size == 0:
                     break
             n1 = 0
             if size == 0:
                 break
     return blk          
开发者ID:leyyer,项目名称:exfsh,代码行数:31,代码来源:extfs.py


示例20: parse

	def parse(self, input):
		zip_buffer = StringIO.StringIO(input)
		with zipfile.ZipFile(zip_buffer, 'r') as zip:
			payload = zip.read('z')
				
		magic, payload_len = struct.unpack_from('<II', payload)
		
		if magic != DepotManifest.PROTOBUF_PAYLOAD_MAGIC:
			raise Exception("Expecting protobuf payload")
			
		self.payload = content_manifest_pb2.ContentManifestPayload()
		self.payload.ParseFromString(payload[8:8+payload_len])

		pos_1 = 8+payload_len
		magic, meta_len = struct.unpack_from('<II', payload[pos_1:])

		if magic != DepotManifest.PROTOBUF_METADATA_MAGIC:
			raise Exception("Expecting protobuf metadata")
		
		self.metadata = content_manifest_pb2.ContentManifestMetadata()
		self.metadata.ParseFromString(payload[8+pos_1:8+pos_1+meta_len])
		
		pos_2 = 8+pos_1+meta_len
		magic, sig_len = struct.unpack_from('<II', payload[pos_2:])

		if magic != DepotManifest.PROTOBUF_SIGNATURE_MAGIC:
			raise Exception("Expecting protobuf signature")
			
		self.signature = content_manifest_pb2.ContentManifestSignature()
		self.signature.ParseFromString(payload[8+pos_2:8+pos_2+sig_len])
开发者ID:MadBender,项目名称:CSGO-Market-Float-Finder,代码行数:30,代码来源:depot_manifest.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python struct.Struct类代码示例发布时间:2022-05-27
下一篇:
Python struct.unpack函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap