10 #ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H 11 #define LLVM_SUPPORT_BINARYBYTESTREAM_H 35 : Endian(Endian), Data(Data) {}
37 : Endian(Endian), Data(Data.bytes_begin(), Data.bytes_end()) {}
62 const char *CharData =
reinterpret_cast<const char *
>(
Data.
data());
80 MemBuffer(
std::move(Buffer)) {}
94 : Data(Data), ImmutableStream(Data, Endian) {}
97 return ImmutableStream.getEndian();
102 return ImmutableStream.readBytes(Offset, Size, Buffer);
107 return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);
116 if (
auto EC = checkOffsetForWrite(Offset, Buffer.
size()))
119 uint8_t *DataPtr =
const_cast<uint8_t *
>(
Data.
data());
120 ::memcpy(DataPtr + Offset, Buffer.
data(), Buffer.
size());
136 std::vector<uint8_t>
Data;
150 if (
auto EC = checkOffsetForWrite(Offset, Buffer.
size()))
163 if (
auto EC = checkOffsetForWrite(Offset, 1))
186 if (RequiredSize > Data.size())
187 Data.resize(RequiredSize);
209 StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
213 Buffer->getBufferEnd()),
215 FileBuffer(std::move(Buffer)) {}
217 Error commit()
override {
218 if (FileBuffer->commit())
219 return make_error<BinaryStreamError>(
225 uint8_t *getBufferStart()
const {
return FileBuffer->getBufferStart(); }
228 uint8_t *getBufferEnd()
const {
return FileBuffer->getBufferEnd(); }
231 std::unique_ptr<FileOutputBuffer> FileBuffer;
237 : Impl(
std::move(Buffer), Endian) {}
240 return Impl.getEndian();
245 return Impl.readBytes(Offset, Size, Buffer);
250 return Impl.readLongestContiguousChunk(Offset, Buffer);
256 return Impl.writeBytes(Offset, Data);
273 #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.