mirror of
https://github.com/openXC7/prjxray.git
synced 2026-08-22 14:06:54 +02:00
lib: accessor to get contents of a memory-mapped file as bytes
MemoryMappedFile's data() method returns a void* as it has no idea what type the contents are. Viewing it as bytes is a very common operation so add a convience method that wraps the pointer in a Span<uint8_t>. Signed-off-by: Rick Altherr <[email protected]>
This commit is contained in:
+2
-4
@@ -78,10 +78,8 @@ int main(int argc, char **argv) {
|
||||
std::cout << "Bitstream size: " << in_file->size() << " bytes"
|
||||
<< std::endl;
|
||||
|
||||
auto in_bytes = absl::Span<uint8_t>(
|
||||
static_cast<uint8_t*>(in_file->data()),
|
||||
in_file->size());
|
||||
reader = xc7series::BitstreamReader::InitWithBytes(in_bytes);
|
||||
reader = xc7series::BitstreamReader::InitWithBytes(
|
||||
in_file->as_bytes());
|
||||
} else {
|
||||
std::vector<uint8_t> bitdata;
|
||||
while (1) {
|
||||
|
||||
+2
-4
@@ -31,10 +31,8 @@ int ListConfigPackets(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto in_bytes = absl::Span<uint8_t>(
|
||||
static_cast<uint8_t*>(in_file->data()),
|
||||
in_file->size());
|
||||
auto reader = xc7series::BitstreamReader::InitWithBytes(in_bytes);
|
||||
auto reader = xc7series::BitstreamReader::InitWithBytes(
|
||||
in_file->as_bytes());
|
||||
if (!reader) {
|
||||
std::cerr << "Input doesn't look like a bitstream"
|
||||
<< std::endl;
|
||||
|
||||
@@ -31,10 +31,8 @@ int main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto in_bytes = absl::Span<uint8_t>(
|
||||
static_cast<uint8_t*>(in_file->data()),
|
||||
in_file->size());
|
||||
auto reader = xc7series::BitstreamReader::InitWithBytes(in_bytes);
|
||||
auto reader = xc7series::BitstreamReader::InitWithBytes(
|
||||
in_file->as_bytes());
|
||||
if (!reader) {
|
||||
std::cerr << "Input doesn't look like a bitstream"
|
||||
<< std::endl;
|
||||
|
||||
Reference in New Issue
Block a user