def view_from_backing(cls: Type[BL], node: Node, hook: Optional[ViewHook] = None) -> BL: contents_depth = cls.contents_depth() contents_node = node.get_left() length = uint256.view_from_backing(node.get_right()) if length > cls.limit(): raise Exception("ByteList backing declared length exceeds limit") if contents_depth == 0: return cls.decode_bytes(contents_node.root[:length]) else: chunk_count = (length + 31) // 32 chunks = [contents_node.getter(to_gindex(i, contents_depth)) for i in range(chunk_count)] bytez = b"".join(ch.root for ch in chunks)[:length] return cls.decode_bytes(bytez)
def length(self) -> int: ll_node = super().get_backing().get_right() ll = cast(uint256, uint256.view_from_backing(node=ll_node, hook=None)) return int(ll)