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());
81 MemBuffer(
std::move(Buffer)) {}
95 : Data(Data), ImmutableStream(Data, Endian) {}
98 return ImmutableStream.getEndian();
103 return ImmutableStream.readBytes(Offset, Size, Buffer);
108 return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);
117 if (
auto EC = checkOffsetForWrite(Offset, Buffer.
size()))
120 uint8_t *DataPtr =
const_cast<uint8_t *
>(
Data.
data());
137 std::vector<uint8_t>
Data;
151 if (
auto EC = checkOffsetForWrite(Offset, Buffer.
size()))
164 if (
auto EC = checkOffsetForWrite(Offset, 1))
187 if (RequiredSize > Data.size())
188 Data.resize(RequiredSize);
210 StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
214 Buffer->getBufferEnd()),
216 FileBuffer(std::move(Buffer)) {}
218 Error commit()
override {
219 if (FileBuffer->commit())
220 return make_error<BinaryStreamError>(
226 uint8_t *getBufferStart()
const {
return FileBuffer->getBufferStart(); }
229 uint8_t *getBufferEnd()
const {
return FileBuffer->getBufferEnd(); }
232 std::unique_ptr<FileOutputBuffer> FileBuffer;
238 : Impl(
std::move(Buffer), Endian) {}
241 return Impl.getEndian();
246 return Impl.readBytes(Offset, Size, Buffer);
251 return Impl.readLongestContiguousChunk(Offset, Buffer);
257 return Impl.writeBytes(Offset, Data);
274 #endif // LLVM_SUPPORT_BYTESTREAM_H std::unique_ptr< MemoryBuffer > MemBuffer
uint32_t getLength() override
Return the number of bytes of data in this stream.
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...
This class represents lattice values for constants.
MutableArrayRef< uint8_t > data() const
AppendingBinaryByteStream(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...
uint8_t * getBufferEnd() const
Returns a pointer to the end of the buffer.
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.
void insert(uint32_t Offset, ArrayRef< uint8_t > Bytes)
uint32_t getLength() override
Return the number of bytes of data in this stream.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
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...
Error checkOffsetForRead(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...
ArrayRef< uint8_t > data() const
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.
MutableBinaryByteStream(MutableArrayRef< uint8_t > Data, llvm::support::endianness Endian)
Error commit() override
For buffered streams, commits changes to the backing store.
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.
size_t size() const
size - Get the array size.
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
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
An implementation of WritableBinaryStream which can write at its end causing the underlying data to g...
llvm::support::endianness getEndian() const override
static ErrorSuccess success()
Create a success value.
MutableArrayRef< uint8_t > data()
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
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...
BinaryByteStream(ArrayRef< uint8_t > Data, llvm::support::endianness Endian)
virtual BinaryStreamFlags getFlags() const override
Return the properties of this stream.
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.
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.
Error writeBytes(uint32_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
bool empty() const
empty - Check if the array is empty.
A BinaryStream which can be read from as well as written to.