'Test performance of encode/decode cycle.'

def testEncodeDecode(self):

    def Check(s, new_s):
        self.assertEqual(s.name, new_s.name)
        self.assertEqual(s.name, u'foo')
        self.assertEqual(s.request_id, new_s.request_id)
        self.assertEqual(s.request_id, 1)
        self.assertEqual(s.response_id, new_s.response_id)
        self.assertEqual(s.response_id, 1)
        self.assertEqual(s.session_id, new_s.session_id)
        self.assertEqual(s.session_id, u'session')
    def ProtoEncodeDecode():
        s = jobs_pb2.GrrMessage(name=u'foo', request_id=1, response_id=1, session_id=u'session')
        data = s.SerializeToString()
        new_s = jobs_pb2.GrrMessage()
        new_s.ParseFromString(data)
        return (s, new_s)
    def RDFStructEncodeDecode():
        s = StructGrrMessage(name=u'foo', request_id=1, response_id=1, session_id=u'session')
        data = s.SerializeToString()
        new_s = StructGrrMessage.FromSerializedString(data)
        return (s, new_s)
    Check(*ProtoEncodeDecode())
    Check(*RDFStructEncodeDecode())
    self.TimeIt(RDFStructEncodeDecode)
    self.TimeIt(ProtoEncodeDecode)
