11 #ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H
12 #define LLVM_SUPPORT_BINARYBYTESTREAM_H
36 : Endian(Endian), Data(Data) {}
38 : Endian(Endian), Data(Data.bytes_begin(), Data.bytes_end()) {}
63 const char *CharData =
reinterpret_cast<const char *
>(
Data.
data());
95 : Data(Data), ImmutableStream(Data, Endian) {}
103 return ImmutableStream.
readBytes(Offset, Size, Buffer);
120 uint8_t *DataPtr =
const_cast<uint8_t *
>(Data.
data());
121 ::memcpy(DataPtr + Offset, Buffer.
data(), Buffer.
size());
140 StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
144 Buffer->getBufferEnd()),
146 FileBuffer(std::move(Buffer)) {}
149 if (FileBuffer->commit())
150 return make_error<BinaryStreamError>(
156 std::unique_ptr<FileOutputBuffer> FileBuffer;
162 : Impl(std::move(Buffer), Endian) {}
165 return Impl.getEndian();
170 return Impl.readBytes(Offset, Size, Buffer);
175 return Impl.readLongestContiguousChunk(Offset, Buffer);
181 return Impl.writeBytes(Offset, Data);
192 #endif // LLVM_SUPPORT_BYTESTREAM_H
MutableBinaryByteStream()=default
std::unique_ptr< MemoryBuffer > MemBuffer
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
Error checkOffset(uint32_t Offset, uint32_t DataSize)
Error readBytes(uint32_t Offset, uint32_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
Error readLongestContiguousChunk(uint32_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
uint32_t getLength() override
Return the number of bytes of data in this stream.
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...
ArrayRef< uint8_t > data() const
Error readBytes(uint32_t Offset, uint32_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...
MutableBinaryByteStream(MutableArrayRef< uint8_t > Data, llvm::support::endianness Endian)
size_t size() const
size - Get the array size.
Error commit() override
For buffered streams, commits changes to the backing store.
An interface for accessing data in a stream-like format, but which discourages copying.
Error writeBytes(uint32_t Offset, ArrayRef< uint8_t > Data) override
Attempt to write the given bytes into the stream at the desired offset.
bool empty() const
empty - Check if the array is empty.
Error readLongestContiguousChunk(uint32_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
An implementation of BinaryStream whose data is backed by an llvm MemoryBuffer object.
BinaryByteStream()=default
llvm::support::endianness getEndian() const override
static ErrorSuccess success()
Create a success value.
llvm::support::endianness getEndian() const override
Error commit() override
For buffered streams, commits changes to the backing store.
BinaryByteStream(StringRef Data, llvm::support::endianness Endian)
llvm::support::endianness Endian
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
BinaryByteStream(ArrayRef< uint8_t > Data, llvm::support::endianness Endian)
uint32_t getLength() override
Return the number of bytes of data in this stream.
MemoryBufferByteStream(std::unique_ptr< MemoryBuffer > Buffer, llvm::support::endianness Endian)
Error readBytes(uint32_t Offset, uint32_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...
FileBufferByteStream(std::unique_ptr< FileOutputBuffer > Buffer, llvm::support::endianness Endian)
Error readLongestContiguousChunk(uint32_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
MutableArrayRef< uint8_t > data() const
Lightweight error class with error context and mandatory checking.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
StringRef - Represent a constant reference to a string, i.e.
uint32_t getLength() override
Return the number of bytes of data in this stream.
Error writeBytes(uint32_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
A BinaryStream which can be read from as well as written to.