Пример #1
0
 def test_parent_references(self):
     msg = Struct('foo', 'foo_type')
     child = Struct('sub', 'subelement_type')
     child['field'] = uint_field()
     msg['subbi'] = child
     self.assertEquals(msg, child._parent)
     self.assertEquals(msg, child['field']._parent._parent)
Пример #2
0
 def test_in(self):
     msg = Struct('foo', 'foo_type')
     msg['a'] = uint_field()
     msg['b'] = uint_field()
     msg['c'] = uint_field()
     self.assertTrue('a' in msg)
     self.assertFalse('d' in msg)
def create_message(params):
    struct = Struct('foo', 'foo_type')
    for key in params:
        struct[key] = uint_field(params[key])
    return struct
Пример #4
0
 def _get_struct(self, name, parent):
     struct = Struct(name or self.name, self.type, align=self._align)
     struct._parent = parent
     return struct
Пример #5
0
 def test_not_iterable(self):
     msg = Struct('foo', 'foo_type')
     msg['a'] = uint_field()
     self.assertRaises(TypeError, iter, msg)
     self.assertRaises(TypeError, iter, msg.a)
Пример #6
0
 def test_decode_dynamic_with_subtractor(self):
     msg = Struct('foo', 'foo_type')
     msg['len'] = Field('uint', 'len', to_bin('0x04'))
     dyn_len = Length('len-2')
     self.assertEqual(dyn_len.decode(msg), 2)
Пример #7
0
 def _get_struct(self, name, parent):
     struct = Struct(name or self.name, self.type, align=self._align)
     struct._parent = parent
     return struct
Пример #8
0
 def test_decode_dynamic(self):
     msg = Struct('foo', 'foo_type')
     msg['len'] = Field('uint', 'len', to_bin('0x04'))
     dyn_len = Length('len')
     self.assertEquals(dyn_len.decode(msg), 4)