(self,dpack)
return {'result':True,'command':command,'length':length}
解包
解包
解包
def unpack(self,dpack):
        '''解包
        '''
        try:
            ud = struct.unpack('!sssss3I',dpack)
        except struct.error,de:
            log.err(de,traceback.format_exc())
            return {'result':False,'command':0,'length':0}
        HEAD_0 = ord(ud[0])
        HEAD_1 = ord(ud[1])
        HEAD_2 = ord(ud[2])
        HEAD_3 = ord(ud[3])
        protoVersion = ord(ud[4])
        serverVersion = ud[5]
        length = ud[6]-4
        command = ud[7]
        if HEAD_0 <>self.HEAD_0 or HEAD_1<>self.HEAD_1 or\
             HEAD_2<>self.HEAD_2 or HEAD_3<>self.HEAD_3 or\
              protoVersion<>self.protoVersion or serverVersion<>self.serverVersion:
            return {'result':False,'command':0,'length':0}
        return {'result':True,'command':command,'length':length}
def unpack ( self , dpack ) : try : ud = struct . unpack ( '!sssss3I' , dpack ) except struct . error , de : log . err ( de , traceback . format_exc ( ) ) return { 'result' : False , 'command' : 0 , 'length' : 0 } HEAD_0 = ord ( ud [ 0 ] ) HEAD_1 = ord ( ud [ 1 ] ) HEAD_2 = ord ( ud [ 2 ] ) HEAD_3 = ord ( ud [ 3 ] ) protoVersion = ord ( ud [ 4 ] ) serverVersion = ud [ 5 ] length = ud [ 6 ] - 4 command = ud [ 7 ] if HEAD_0 <> self . HEAD_0 or HEAD_1 <> self . HEAD_1 or HEAD_2 <> self . HEAD_2 or HEAD_3 <> self . HEAD_3 or protoVersion <> self . protoVersion or serverVersion <> self . serverVersion : return { 'result' : False , 'command' : 0 , 'length' : 0 } return { 'result' : True , 'command' : command , 'length' : length }