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:
Rick Altherr
2018-01-04 11:17:59 -08:00
parent 5a155de8bc
commit a4858be23a
5 changed files with 14 additions and 14 deletions
+2 -4
View File
@@ -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
View File
@@ -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;
+2 -4
View File
@@ -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;