20 RawMemoryObject(
const unsigned char *Start,
const unsigned char *End) :
21 FirstChar(Start), LastChar(End) {
22 assert(LastChar >= FirstChar &&
"Invalid start/end range");
25 uint64_t getExtent()
const override {
26 return LastChar - FirstChar;
28 uint64_t readBytes(uint8_t *Buf, uint64_t Size,
29 uint64_t
Address)
const override;
30 const uint8_t *getPointer(uint64_t address, uint64_t
size)
const override;
31 bool isValidAddress(uint64_t address)
const override {
32 return validAddress(address);
36 const uint8_t*
const FirstChar;
37 const uint8_t*
const LastChar;
41 bool validAddress(uint64_t address)
const {
42 return static_cast<std::ptrdiff_t
>(address) < LastChar - FirstChar;
45 RawMemoryObject(
const RawMemoryObject&) =
delete;
46 void operator=(
const RawMemoryObject&) =
delete;
49 uint64_t RawMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
51 uint64_t BufferSize = LastChar - FirstChar;
52 if (Address >= BufferSize)
55 uint64_t End = Address + Size;
59 assert(static_cast<int64_t>(End - Address) >= 0);
61 memcpy(Buf, Address + FirstChar, Size);
65 const uint8_t *RawMemoryObject::getPointer(uint64_t address,
66 uint64_t
size)
const {
67 return FirstChar + address;
75 if (ObjectSize && address < ObjectSize)
return true;
76 return fetchToPos(address);
80 if (ObjectSize)
return ObjectSize;
81 size_t pos = BytesRead + kChunkSize;
83 while (fetchToPos(pos)) pos += kChunkSize;
88 uint64_t Address)
const {
89 fetchToPos(Address + Size - 1);
94 (ObjectSize && ObjectSize < BytesRead) ? ObjectSize : BytesRead;
95 if (Address >= MaxAddress)
98 uint64_t End = Address + Size;
101 assert(End >= Address);
103 memcpy(Buf, &Bytes[Address + BytesSkipped], Size);
108 if (BytesRead < s)
return true;
117 if (ObjectSize <= BytesRead)
122 const unsigned char *End) {
123 return new RawMemoryObject(Start, End);
127 std::unique_ptr<DataStreamer> Streamer)
128 : Bytes(kChunkSize), Streamer(std::move(Streamer)), BytesRead(0),
129 BytesSkipped(0), ObjectSize(0), EOFReached(
false) {
130 BytesRead = this->Streamer->GetBytes(&Bytes[0], kChunkSize);
bool isValidAddress(uint64_t address) const override
Returns true if the address is within the object (i.e.
uint64_t getExtent() const override
Returns the size of the region in bytes.
Interface to data which might be streamed.
uint64_t readBytes(uint8_t *Buf, uint64_t Size, uint64_t Address) const override
Tries to read a contiguous range of bytes from the region, up to the end of the region.
void setKnownObjectSize(size_t size)
If the data object size is known in advance, many of the operations can be made more efficient...
StreamingMemoryObject(std::unique_ptr< DataStreamer > Streamer)
bool dropLeadingBytes(size_t s)
Drop s bytes from the front of the stream, pushing the positions of the remaining bytes down by s...
MemoryObject * getNonStreamedMemoryObject(const unsigned char *Start, const unsigned char *End)