def parse(opcodes, source): template = Template('test', opcodes) s = BCDataStream() for t in source: if isinstance(t, bytes): s.write_many(push_data(t)) elif isinstance(t, int): s.write_uint8(t) else: raise ValueError() s.reset() return template.parse(tokenize(s))
def test_write_read(self): s = BCDataStream() s.write_string(b'a' * 252) s.write_string(b'b' * 254) s.write_string(b'c' * (0xFFFF + 1)) # s.write_string(b'd'*(0xFFFFFFFF + 1)) s.write_boolean(True) s.write_boolean(False) s.reset() self.assertEqual(s.read_string(), b'a' * 252) self.assertEqual(s.read_string(), b'b' * 254) self.assertEqual(s.read_string(), b'c' * (0xFFFF + 1)) # self.assertEqual(s.read_string(), b'd'*(0xFFFFFFFF + 1)) self.assertTrue(s.read_boolean()) self.assertFalse(s.read_boolean())