コード例 #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)
コード例 #3
0
def create_message(params):
    struct = Struct('foo', 'foo_type')
    for key in params:
        struct[key] = uint_field(params[key])
    return struct
コード例 #4
0
ファイル: containers.py プロジェクト: aleskarovadi/Rammbock
 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)