def decode_packet(packet_buff):
 if (len(packet_buff) < 4):
  raise InvalidPacketException((u'Packet too small (<4): %s' % hexlify(packet_buff)))
 (opcode, session_id) = struct.unpack_from('!HH', packet_buff, 0)
 if (opcode not in PACKET_DECODE_DICT):
  raise InvalidPacketException((u'Invalid opcode: %s' % opcode))
 packet = {'opcode': opcode, 'session_id': session_id}
 return PACKET_DECODE_DICT[opcode](packet, packet_buff, 4)

def decode_packet ( packet_buff ) : if ( len ( packet_buff ) < 4 ) : raise InvalidPacketException ( ( u'Packet too small (<4): %s' % hexlify ( packet_buff ) ) ) ( opcode , session_id ) = struct . unpack_from ( '!HH' , packet_buff , 0 ) if ( opcode not in PACKET_DECODE_DICT ) : raise InvalidPacketException ( ( u'Invalid opcode: %s' % opcode ) ) packet = { 'opcode' : opcode , 'session_id' : session_id } return PACKET_DECODE_DICT [ opcode ] ( packet , packet_buff , 4 )
decodes a packet binary string into a packet dictionary .