mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-29 17:30:09 +02:00
Add a Layout.read_bytes() method that reads a layout from a byte array in Python or Ruby.
This is much more convenient and a bit more efficient than writing the bytes to a temporary file and reading that back in. It's useful when we have received a layout over the network or embedded in some file. This makes a copy of the bytes but there doesn't seem to be any way to avoid that currently.
This commit is contained in:
Vendored
+21
@@ -1200,6 +1200,27 @@ class DBLayoutTest(unittest.TestCase):
|
||||
self.assertEqual(str(t), "r180 0,0")
|
||||
|
||||
|
||||
def test_read_bytes(self):
|
||||
|
||||
testtmp = os.getenv("TESTTMP_WITH_NAME", os.getenv("TESTTMP", "."))
|
||||
|
||||
file_gds = os.path.join(testtmp, "bytes.gds")
|
||||
|
||||
ly = pya.Layout()
|
||||
top = ly.create_cell("TOP")
|
||||
l1 = ly.layer(1, 0)
|
||||
shape = top.shapes(l1).insert(pya.Box(0, 10, 20, 30))
|
||||
ly.write(file_gds)
|
||||
|
||||
with open(file_gds, "rb") as f:
|
||||
byte_buffer = f.read()
|
||||
|
||||
ly2 = pya.Layout()
|
||||
ly2.read_bytes(byte_buffer, pya.LoadLayoutOptions())
|
||||
l2 = ly2.layer(1, 0)
|
||||
self.assertEqual(ly2.top_cell().bbox().to_s(), "(0,10;20,30)")
|
||||
|
||||
|
||||
# run unit tests
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(DBLayoutTest)
|
||||
|
||||
Reference in New Issue
Block a user