Skip to content

Commit 7da0601

Browse files
committed
lib.data: Add View.get() and View.set().
1 parent 20c9e93 commit 7da0601

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

amaranth/lib/data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,22 @@ def eq(self, other):
660660
"""
661661
return self.as_value().eq(other)
662662

663+
async def get(self):
664+
if isinstance(self.__layout, ArrayLayout):
665+
return [await self[idx].get() for idx in range(self.__layout.length)]
666+
667+
else:
668+
return {name: await self[name].get() for name in self.__layout.members}
669+
670+
async def set(self, value):
671+
if isinstance(self.__layout, ArrayLayout):
672+
for i, v in enumerate(value):
673+
await self[i].set(v)
674+
675+
else:
676+
for k, v in value.items():
677+
await self[k].set(v)
678+
663679
def __getitem__(self, key):
664680
"""Slice the underlying value.
665681

0 commit comments

Comments
 (0)