10#ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H
11#define LLVM_SUPPORT_BINARYBYTESTREAM_H
61 const char *CharData =
reinterpret_cast<const char *
>(
Data.
data());
118 uint8_t *DataPtr =
const_cast<uint8_t *
>(Data.
data());
135 std::vector<uint8_t> Data;
185 if (RequiredSize >
Data.size())
186 Data.resize(RequiredSize);
206 StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
210 Buffer->getBufferEnd()),
212 FileBuffer(std::move(Buffer)) {}
214 Error commit()
override {
215 if (FileBuffer->commit())
216 return make_error<BinaryStreamError>(
222 uint8_t *getBufferStart()
const {
return FileBuffer->getBufferStart(); }
225 uint8_t *getBufferEnd()
const {
return FileBuffer->getBufferEnd(); }
228 std::unique_ptr<FileOutputBuffer> FileBuffer;
237 return Impl.getEndian();
247 return Impl.readLongestContiguousChunk(
Offset, Buffer);
An implementation of WritableBinaryStream which can write at its end causing the underlying data to g...
BinaryStreamFlags getFlags() const override
Return the properties of this stream.
llvm::support::endianness getEndian() const override
AppendingBinaryByteStream(llvm::support::endianness Endian)
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
Error commit() override
For buffered streams, commits changes to the backing store.
MutableArrayRef< uint8_t > data()
uint64_t getLength() override
Return the number of bytes of data in this stream.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
void insert(uint64_t Offset, ArrayRef< uint8_t > Bytes)
AppendingBinaryByteStream()=default
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
ArrayRef< uint8_t > data() const
BinaryByteStream(ArrayRef< uint8_t > Data, llvm::support::endianness Endian)
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
BinaryByteStream()=default
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
llvm::support::endianness getEndian() const override
uint64_t getLength() override
Return the number of bytes of data in this stream.
BinaryByteStream(StringRef Data, llvm::support::endianness Endian)
llvm::support::endianness Endian
An interface for accessing data in a stream-like format, but which discourages copying.
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
uint64_t getLength() override
Return the number of bytes of data in this stream.
llvm::support::endianness getEndian() const override
Error commit() override
For buffered streams, commits changes to the backing store.
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Data) override
Attempt to write the given bytes into the stream at the desired offset.
uint8_t * getBufferEnd() const
Returns a pointer to the end of the buffer.
FileBufferByteStream(std::unique_ptr< FileOutputBuffer > Buffer, llvm::support::endianness Endian)
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
An implementation of BinaryStream whose data is backed by an llvm MemoryBuffer object.
std::unique_ptr< MemoryBuffer > MemBuffer
MemoryBufferByteStream(std::unique_ptr< MemoryBuffer > Buffer, llvm::support::endianness Endian)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
MutableArrayRef< uint8_t > data() const
uint64_t getLength() override
Return the number of bytes of data in this stream.
Error commit() override
For buffered streams, commits changes to the backing store.
llvm::support::endianness getEndian() const override
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
MutableBinaryByteStream()=default
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
MutableBinaryByteStream(MutableArrayRef< uint8_t > Data, llvm::support::endianness Endian)
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
StringRef - Represent a constant reference to a string, i.e.
A BinaryStream which can be read from as well as written to.
Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize)
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.