Closed bessman closed 11 months ago
Good suggestion (probably). Part of version 18.0.0.
In case this breaks peoples code, I could add aliases like _Segments = Segments
. I think I'll do that actually.
Great! Here's another, related suggestion: Segment.chunks
should yield smaller Segment
s instead of Chunks
.
My use case is that I need to split a Segment
into chunks for writing to a target device. Then I need to split those chunks into smaller chunks in order to calculate a checksum of the larger chunk. But Chunk
doesn't have a .chunks
method, so that doesn't work :(
Instead, I created a new Segment
and chunked that:
Segment(chunk.address, chunk.address + len(chunk.data), chunk.data, 1).chunks()
But is there any reason chunks
can't just yield Segments
to begin with?
Not that I can think of, but was some time I used bincopy so I might have forgotten. If you have time you could submit a PR with the change and I can have a closer look (and maybe you encounter some problem).
Segment._word_size_bytes
should have a public getter. It is useful to be able to get chunks of a certain number of bytes, for example when calculating a checksum. Since .chunks
wants the size and alignment in words, it is necessary to know the word size to get a certain number of bytes per chunk. The Segment
knows it internally, but it's only public on the BinFile
, which may not be available in a subroutine.
Feel free to make it public on Segment as well.
It would be nice to be able to use these types in annotations:
instead of having to write:
which is both harder on the eyes and makes various linters complain about accessing protected members.