'Test serialization and construction of repeated fields.'

def testRepeatedFields(self):

    repeats = (self.REPEATS / 50)
    def ProtoCreateAndSerialize():
        s = jobs_pb2.MessageList()
        for i in range(self.REPEATS):
            s.job.add(session_id='test', name='foobar', request_id=i)
        return len(s.SerializeToString())
    def RDFStructCreateAndSerialize():
        s = FastGrrMessageList()
        for i in range(self.REPEATS):
            s.job.Append(session_id='test', name='foobar', request_id=i)
        return len(s.SerializeToString())
    self.TimeIt(RDFStructCreateAndSerialize, 'RDFStruct    Repeated    Fields', repetitions=repeats)
    self.TimeIt(ProtoCreateAndSerialize, 'Protobuf    Repeated    Fields', repetitions=repeats)
    s = jobs_pb2.MessageList()
    for i in range(self.REPEATS):
        s.job.add(session_id='test', name='foobar', request_id=i)
    serialized = s.SerializeToString()
    unserialized = FastGrrMessageList.FromSerializedString(serialized)
    self.assertEqual(len(unserialized.job), len(s.job))
    self.assertEqual(unserialized.job[134].session_id, 'test')
    self.assertEqual(unserialized.job[100].request_id, 100)
