本文整理汇总了Python中spock.mcp.datautils.pack函数的典型用法代码示例。如果您正苦于以下问题:Python pack函数的具体用法?Python pack怎么用?Python pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pack函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode_extra
def encode_extra(packet):
o = b''
act = packet.data['action']
if act == mcdata.SO_CREATE_BOARD or act == mcdata.SO_UPDATE_BOARD:
o += datautils.pack(MC_STRING, packet.data['obj_val'])
o += datautils.pack(MC_STRING, packet.data['type'])
return o
示例2: encode_extra
def encode_extra(packet):
o = datautils.pack('int', len(packet.data['blocks']))
for block in packet.data['blocks']:
for coord in block:
o += datautils.pack('byte', coord)
o += datautils.pack('float', packet.data['player_x'])
o += datautils.pack('float', packet.data['player_y'])
o += datautils.pack('float', packet.data['player_z'])
return o
示例3: encode
def encode(self):
#Ident
o = datautils.pack('ubyte', self.__ident[2])
#Payload
for dtype, name in mcdata.hashed_structs[self.__hashed_ident]:
o += datautils.pack(dtype, self.data[name])
#Extension
if self.__hashed_ident in hashed_extensions:
o += hashed_extensions[self.__hashed_ident].encode_extra(self)
return datautils.pack('varint', len(o)) + o
示例4: encode_extra
def encode_extra(packet):
o = datautils.pack(MC_SHORT, len(packet.data['blocks']))
o += datautils.pack(MC_INT, 4*len(packet.data['blocks']))
for block in packet.data['blocks']:
o += datautils.pack(MC_UINT,
block['metadata'] +
(block['type']<<4) +
(block['y'] << 16) +
(block['z'] << 24) +
(block['x'] << 28)
)
return o
示例5: encode_extra
def encode_extra(self, packet):
packet.data['data_size'] = len(packet.data['data'])
append = packet.data['data']
for d in packet.data["bitmaps"]:
append += pack('int', d['x'])
append += pack('int', d['z'])
append += pack('short', d['primary_bitmap'])
append += pack('short', d['secondary_bitmap'])
return append
示例6: encode
def encode(self):
#Ident
o = datautils.pack(MC_VARINT, self.id)
#Payload
for dtype, name in mcdata.hashed_structs[self.__hashed_ident]:
o += datautils.pack(dtype, self.data[name])
#Extension
if self.__hashed_ident in hashed_extensions:
o += hashed_extensions[self.__hashed_ident].encode_extra(self)
self.length = len(o)
return datautils.pack(MC_VARINT, self.length) + o
示例7: encode
def encode(self):
#Ident
output = datautils.pack('ubyte', self.ident)
#Extension
if self.ident in mcpacket_extensions.extensions:
append = mcpacket_extensions.extensions[self.ident].encode_extra(self)
else:
append = b''
#Payload
for dtype, name in mcdata.structs[self.ident][self.direction]:
output += datautils.pack(dtype, self.data[name])
return output + append
示例8: encode
def encode(self, proto_comp_state, proto_comp_threshold, comp_level = 6):
#Ident
o = datautils.pack(MC_VARINT, self.ident[2])
#Payload
for dtype, name in mcdata.hashed_structs[self.ident]:
o += datautils.pack(dtype, self.data[name])
#Extension
if self.ident in hashed_extensions:
o += hashed_extensions[self.ident].encode_extra(self)
if proto_comp_state == mcdata.PROTO_COMP_ON:
uncompressed_len = len(o)
if uncompressed_len < proto_comp_threshold:
header = datautils.pack(MC_VARINT, uncompressed_len + 1)
header += datautils.pack(MC_VARINT, 0)
elif uncompressed_len >= proto_comp_threshold:
o = zlib.compress(o, comp_level)
ulen_varint = datautils.pack(MC_VARINT, uncompressed_len)
header = datautils.pack(MC_VARINT, uncompressed_len + len(ulen_varint))
header += ulen_varint
return header + o
elif proto_comp_state == mcdata.PROTO_COMP_OFF:
return datautils.pack(MC_VARINT, len(o)) + o
else:
return None
示例9: encode_extra
def encode_extra(packet):
act = packet.data['action']
o = b''
if act in [mcdata.TE_CREATE_TEAM, mcdata.TE_UPDATE_TEAM]:
o += datautils.pack(MC_STRING, packet.data['display_name'])
o += datautils.pack(MC_STRING, packet.data['team_prefix'])
o += datautils.pack(MC_STRING, packet.data['team_suffix'])
o += datautils.pack(MC_BYTE, packet.data['friendly_fire'])
o += datautils.pack(MC_STRING, packet.data['name_visibility'])
o += datautils.pack(MC_BYTE, packet.data['color'])
if act in [mcdata.TE_CREATE_TEAM, mcdata.TE_ADDPLY_TEAM,
mcdata.TE_REMPLY_TEAM]:
o += datautils.pack(MC_VARINT, len(packet.data['players']))
for player in packet.data['players']:
o += datautils.pack(MC_STRING, player)
return o
示例10: encode_extra
def encode_extra(packet):
action = packet.data['action']
o = b''
if action == 0 or action == 2:
o += datautils.pack(MC_STRING, packet.data['display_name'])
o += datautils.pack(MC_STRING, packet.data['team_prefix'])
o += datautils.pack(MC_STRING, packet.data['team_suffix'])
o += datautils.pack(MC_BYTE, packet.data['friendly_fire'])
o += datautils.pack(MC_STRING, packet.data['name_visibility'])
if action == 0 or action == 3 or action == 4:
o += datautils.pack(MC_VARINT, len(packet.data['players']))
for player in packet.data['players']:
o += datautils.pack(MC_STRING, player)
return o