def test_file(self): test_filename = "BitStreamTest.bin" writer = BitStreamWriter() writer.write_bits(13, 7) writer.write_string(test_filename) writer.write_varint(-123456) writer.to_file(test_filename) reader = BitStreamReader.from_file(test_filename) self.assertEqual(13, reader.read_bits(7)) self.assertEqual(test_filename, reader.read_string()) self.assertEqual(-123456, reader.read_varint())
def serialize_to_file(obj: typing.Any, filename: str) -> None: """ Serializes generated object to the byte buffer. This is a convenient method for users to easily write given generated object to file. :param obj: Generated object to serialize. :param filename: File to write. :raises PythonRuntimeException: Throws in case of any error during serialization. """ writer = BitStreamWriter() obj.write(writer) writer.to_file(filename)