示例#1
0
    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')
示例#2
0
 class StringTestMessage(Message):
     b = StringField(field_number=2)
示例#3
0
 class TestMsg(Message):
     a = StringField(field_number=1, repeated=True)
示例#4
0
 class TestMsg(Message):
     a = StringField(field_number=1, repeated=True)
     b = MessageField(field_number=2, repeated=True, message_cls=EmbMsg)
示例#5
0
 class EmbMsg(Message):
     a = StringField(field_number=1)
示例#6
0
 class TestMsg(Message):
     a = StringField(field_number=2, optional=True)
示例#7
0
 class EncodedMessage(Message):
     a = StringField(field_number=2)
示例#8
0
 class EncodedMessage(Message):
     a = StringField(field_number=2, repeated=True)
示例#9
0
 class StringTestMessage(Message):
     b = StringField(field_number=1, required=1)
示例#10
0
 class TestMsg(Message):
     a = StringField(field_number=1, optional=True)
     b = StringField(field_number=2, repeated=True)