本文整理汇总了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
示例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))
示例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
示例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
示例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
示例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
示例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
示例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
示例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'))
示例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
示例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)
示例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
示例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
示例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