Example #1
0
    def testDecodeRepeatedFields(self):
        """Test decoding of repeated fields."""

        repeats = self.REPEATS // 50
        s = jobs_pb2.MessageList()
        for i in range(self.REPEATS):
            s.job.add(session_id="test", name="foobar", request_id=i)

        test_data = s.SerializeToString()

        def ProtoDecode():
            s = jobs_pb2.MessageList()
            s.ParseFromString(test_data)

            self.assertEqual(s.job[100].request_id, 100)

        def SProtoDecode():
            s = FastGrrMessageList.FromSerializedBytes(test_data)
            self.assertEqual(s.job[100].request_id, 100)

        self.TimeIt(SProtoDecode,
                    "SProto Repeated Decode",
                    repetitions=repeats)

        self.TimeIt(ProtoDecode,
                    "Protobuf Repeated Decode",
                    repetitions=repeats)
Example #2
0
  def testRepeatedFields(self):
    """Test serialization and construction of repeated fields."""

    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)

    # Check that we can unserialize a protobuf encoded using the standard
    # library.
    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)
Example #3
0
    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())
Example #4
0
    def ProtoDecode():
      s = jobs_pb2.MessageList()
      s.ParseFromString(test_data)

      self.assertEqual(s.job[100].request_id, 100)