def test_add_field(self): class TestMsg(Message): pass TestMsg.add_field('a', StringField(field_number=2, optional=True)) msg = TestMsg() msg.parse_from_bytes(b'\x12\x07\x74\x65\x73\x74\x69\x6E\x67') self.assertTrue(hasattr(msg, 'a')) self.assertEqual(msg.a, 'testing')
class StringTestMessage(Message): b = StringField(field_number=2)
class TestMsg(Message): a = StringField(field_number=1, repeated=True)
class TestMsg(Message): a = StringField(field_number=1, repeated=True) b = MessageField(field_number=2, repeated=True, message_cls=EmbMsg)
class EmbMsg(Message): a = StringField(field_number=1)
class TestMsg(Message): a = StringField(field_number=2, optional=True)
class EncodedMessage(Message): a = StringField(field_number=2)
class EncodedMessage(Message): a = StringField(field_number=2, repeated=True)
class StringTestMessage(Message): b = StringField(field_number=1, required=1)
class TestMsg(Message): a = StringField(field_number=1, optional=True) b = StringField(field_number=2, repeated=True)