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

Python datautils.unpack函数代码示例

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

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



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

示例1: decode

	def decode(self, bbuff, proto_comp_state):
		self.data = {}
		if proto_comp_state == mcdata.PROTO_COMP_ON:
			packet_length = datautils.unpack(MC_VARINT, bbuff)
			start = bbuff.tell()
			data_length = datautils.unpack(MC_VARINT, bbuff)
			packet_data = bbuff.recv(packet_length-(bbuff.tell()-start))
			if data_length:
				packet_data = zlib.decompress(packet_data, zlib.MAX_WBITS)
		elif proto_comp_state == mcdata.PROTO_COMP_OFF:
			packet_data = bbuff.recv(datautils.unpack(MC_VARINT, bbuff))
		else:
			return None

		pbuff = utils.BoundBuffer(packet_data)
		try:
			#Ident
			self.__ident[2] = datautils.unpack(MC_VARINT, pbuff)
			self.ident = tuple(self.__ident)
			self.str_ident = mcdata.packet_ident2str[self.ident]
			#Payload
			for dtype, name in mcdata.hashed_structs[self.ident]:
				self.data[name] = datautils.unpack(dtype, pbuff)
				#Extension
			if self.ident in hashed_extensions:
				hashed_extensions[self.ident].decode_extra(self, pbuff)
			#Not technically an underflow, but we want to do the same thing
			if pbuff.flush():
				raise utils.BufferUnderflowException
		except utils.BufferUnderflowException:
			print('Packet decode failed')
			print('Failed packet ident is probably:', self.str_ident)
			return None
		return self
开发者ID:micropsi-industries,项目名称:spock,代码行数:34,代码来源:mcpacket.py


示例2: decode

    def decode(self, bbuff):
        self.data = {}
        self.length = datautils.unpack(MC_VARINT, bbuff)
        encoded = bbuff.recv(self.length)
        try:
            pbuff = utils.BoundBuffer(encoded)

            #Ident
            self.id = datautils.unpack(MC_VARINT, pbuff)
            self.__hash_ident()

            #Payload
            for dtype, name in mcdata.hashed_structs[self.__hashed_ident]:
                try:
                    self.data[name] = datautils.unpack(dtype, pbuff)
                except BufferUnderflowException:
                    raise Exception("Failed to parse field {0}:{1} from packet {2}".format(name, dtype, repr(self)))

            #Extension
            if self.__hashed_ident in hashed_extensions:
                hashed_extensions[self.__hashed_ident].decode_extra(self, pbuff)

            return self

        except BufferUnderflowException:
            raise Exception("Failed to parse packet: ", repr(self))
开发者ID:conorshankey,项目名称:micropsi2,代码行数:26,代码来源:mcpacket.py


示例3: decode

    def decode(self, bbuff, proto_comp_state):
        self.data = {}
        if proto_comp_state == mcdata.PROTO_COMP_ON:
            packet_length = datautils.unpack(MC_VARINT, bbuff)
            start = bbuff.tell()
            data_length = datautils.unpack(MC_VARINT, bbuff)
            packet_data = bbuff.recv(packet_length - (bbuff.tell() - start))
            if data_length:
                packet_data = zlib.decompress(packet_data, zlib.MAX_WBITS)
        elif proto_comp_state == mcdata.PROTO_COMP_OFF:
            packet_data = bbuff.recv(datautils.unpack(MC_VARINT, bbuff))
        else:
            return None

        pbuff = utils.BoundBuffer(packet_data)
        # Ident
        self.__ident[2] = datautils.unpack(MC_VARINT, pbuff)
        self.__hashed_ident = tuple(self.__ident)
        # Payload
        for dtype, name in mcdata.hashed_structs[self.__hashed_ident]:
            self.data[name] = datautils.unpack(dtype, pbuff)
            # Extension
        if self.__hashed_ident in hashed_extensions:
            hashed_extensions[self.__hashed_ident].decode_extra(self, pbuff)
        return self
开发者ID:nheir,项目名称:spock,代码行数:25,代码来源:mcpacket.py


示例4: decode

    def decode(self, bbuff, proto_comp_state):
        self.data = {}
        packet_length = datautils.unpack(MC_VARINT, bbuff)
        packet_data = bbuff.recv(packet_length)
        pbuff = utils.BoundBuffer(packet_data)
        if proto_comp_state == mcdata.PROTO_COMP_ON:
            body_length = datautils.unpack(MC_VARINT, pbuff)
            if body_length > 0:
                body_data = zlib.decompress(pbuff.flush(), zlib.MAX_WBITS)
                pbuff.write(body_data)
                pbuff.save()

        try:
            # Ident
            self.__ident[2] = datautils.unpack(MC_VARINT, pbuff)
            self.ident = tuple(self.__ident)
            self.str_ident = mcdata.packet_ident2str[self.ident]
            # Payload
            for dtype, name in mcdata.hashed_structs[self.ident]:
                self.data[name] = datautils.unpack(dtype, pbuff)
            # Extension
            if self.ident in hashed_extensions:
                hashed_extensions[self.ident].decode_extra(self, pbuff)
            if len(pbuff) > 0:
                raise PacketDecodeFailure(self, pbuff)
        except utils.BufferUnderflowException:
            raise PacketDecodeFailure(self, pbuff, True)
        return self
开发者ID:MrSwiss,项目名称:SpockBot,代码行数:28,代码来源:mcpacket.py


示例5: decode_extra

 def decode_extra(packet, bbuff):
     packet.data['entries'] = [
         [
             datautils.unpack(MC_STRING, bbuff),
             datautils.unpack(MC_VARINT, bbuff)
         ] for _ in range(datautils.unpack(MC_VARINT, bbuff))]
     return packet
开发者ID:nicoxxl,项目名称:SpockBot,代码行数:7,代码来源:mcpacket_extensions.py


示例6: decode

    def decode(self, bbuff, proto_comp_state):
        self.data = {}
        if proto_comp_state == mcdata.PROTO_COMP_ON:
            packet_length = datautils.unpack(MC_VARINT, bbuff)
            start = bbuff.tell()
            data_length = datautils.unpack(MC_VARINT, bbuff)
            packet_data = bbuff.recv(packet_length-(bbuff.tell()-start))
            if data_length:
                packet_data = zlib.decompress(packet_data, zlib.MAX_WBITS)
        elif proto_comp_state == mcdata.PROTO_COMP_OFF:
            packet_data = bbuff.recv(datautils.unpack(MC_VARINT, bbuff))
        else:
            return None
        pbuff = utils.BoundBuffer(packet_data)

        try:
            #Ident
            self.__ident[2] = datautils.unpack(MC_VARINT, pbuff)
            self.ident = tuple(self.__ident)
            self.str_ident = mcdata.packet_ident2str[self.ident]
            #Payload
            for dtype, name in mcdata.hashed_structs[self.ident]:
                self.data[name] = datautils.unpack(dtype, pbuff)
            #Extension
            if self.ident in hashed_extensions:
                hashed_extensions[self.ident].decode_extra(self, pbuff)
            if pbuff.buff:
                raise PacketDecodeFailure(self, pbuff)
        except utils.BufferUnderflowException:
            raise PacketDecodeFailure(self, pbuff, True)
        return self
开发者ID:guineawheek,项目名称:spock,代码行数:31,代码来源:mcpacket.py


示例7: decode_extra

 def decode_extra(packet, bbuff):
     packet.data['blocks'] = [
         [datautils.unpack(MC_BYTE, bbuff) for j in range(3)]
     for i in range(datautils.unpack(MC_INT, bbuff))]
     packet.data['player_x'] = datautils.unpack(MC_FLOAT, bbuff)
     packet.data['player_y'] = datautils.unpack(MC_FLOAT, bbuff)
     packet.data['player_z'] = datautils.unpack(MC_FLOAT, bbuff)
     return packet
开发者ID:guineawheek,项目名称:spock,代码行数:8,代码来源:mcpacket_extensions.py


示例8: decode_extra

	def decode_extra(packet, bbuff):
		packet.data['blocks'] = [
			[datautils.unpack('byte', bbuff) for j in range(3)]
		for i in range(datautils.unpack('int', bbuff))]
		packet.data['player_x'] = datautils.unpack('float', bbuff)
		packet.data['player_y'] = datautils.unpack('float', bbuff)
		packet.data['player_z'] = datautils.unpack('float', bbuff)
		return packet
开发者ID:pickardjoe,项目名称:spock,代码行数:8,代码来源:mcpacket_extensions.py


示例9: decode_extra

	def decode_extra(self, packet, bbuff):
		if packet.data['mode'] == 0 or packet.data['mode'] == 2:
			packet.data['display_name'] = unpack(bbuff, 'string')
			packet.data['team_prefix'] = unpack(bbuff, 'string')
			packet.data['team_suffix'] = unpack(bbuff, 'string')
		if packet.data['mode'] == 0 or packet.data['mode'] == 3 or packet.data['mode'] == 4:
			packet.data['player_count'] = count = unpack(bbuff, 'short')
			packet.data['players'] = []
			for i in xrange(count):
				packet.data['players'].append(unpack(bbuff, 'string'))
开发者ID:JonnyD,项目名称:spock,代码行数:10,代码来源:mcpacket_extensions.py


示例10: decode

	def decode(self, bbuff):
		self.data = {}
		pbuff = utils.BoundBuffer(bbuff.recv(datautils.unpack('varint', bbuff)))
		#Ident
		self.__ident[2] = datautils.unpack('ubyte', pbuff)
		self.__hashed_ident = tuple(self.__ident)
		#Payload
		for dtype, name in mcdata.hashed_structs[self.__hashed_ident]:
			self.data[name] = datautils.unpack(dtype, pbuff)
		#Extension
		if self.__hashed_ident in hashed_extensions:
			hashed_extensions[self.__hashed_ident].decode_extra(self, pbuff)
		return self
开发者ID:pickardjoe,项目名称:spock,代码行数:13,代码来源:mcpacket.py


示例11: decode

	def decode(self, bbuff):
		#Ident
		self.ident = datautils.unpack(bbuff, 'ubyte')
		
		#print hex(self.ident)
		
		#Payload
		for dtype, name in mcdata.structs[self.ident][self.direction]:
			self.data[name] = datautils.unpack(bbuff, dtype)
		
		#Extension
		if self.ident in mcpacket_extensions.extensions:
			mcpacket_extensions.extensions[self.ident].decode_extra(self, bbuff)
开发者ID:JonnyD,项目名称:spock,代码行数:13,代码来源:mcpacket.py


示例12: decode_extra

	def decode_extra(packet, bbuff):
		assert(datautils.unpack(MC_BYTE, bbuff) == nbt.TAG_COMPOUND)
		name = nbt.TAG_String(buffer = bbuff)
		nbt_data = nbt.TAG_Compound(buffer = bbuff)
		nbt_data.name = name
		packet.data['nbt'] = nbt_data
		return packet
开发者ID:micropsi-industries,项目名称:spock,代码行数:7,代码来源:mcpacket_extensions.py


示例13: decode_extra

 def decode_extra(packet, bbuff):
     count = datautils.unpack(MC_SHORT, bbuff)
     size = datautils.unpack(MC_INT, bbuff)
     packet.data['sky_light'] = datautils.unpack(MC_BOOL, bbuff)
     packet.data['data'] = zlib.decompress(bbuff.recv(size))
     packet.data['metadata'] = [{
         'chunk_x': datautils.unpack(MC_INT, bbuff),
         'chunk_z': datautils.unpack(MC_INT, bbuff),
         'primary_bitmap': datautils.unpack(MC_USHORT, bbuff),
         'add_bitmap': datautils.unpack(MC_USHORT, bbuff),
     } for i in range(count)]
     return packet
开发者ID:OvercastNetwork,项目名称:spock,代码行数:12,代码来源:mcpacket_extensions.py


示例14: decode_extra

	def decode_extra(packet, bbuff):
		action = packet.data['action']
		if action == 0 or action == 2:
			packet.data['display_name'] = datautils.unpack(MC_STRING, bbuff)
			packet.data['team_prefix'] = datautils.unpack(MC_STRING, bbuff)
			packet.data['team_suffix'] = datautils.unpack(MC_STRING, bbuff)
			packet.data['friendly_fire'] = datautils.unpack(MC_BYTE, bbuff)
			packet.data['name_visibility'] = datautils.unpack(MC_STRING, bbuff)
		if action == 0 or action == 3 or action == 4:
			packet.data['players'] = [
				datautils.unpack(MC_STRING, bbuff)
			for i in range(datautils.unpack(MC_VARINT, bbuff))]
		return packet
开发者ID:nheir,项目名称:spock,代码行数:13,代码来源:mcpacket_extensions.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python common.handle_error函数代码示例发布时间:2022-05-27
下一篇:
Python datautils.pack函数代码示例发布时间: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