class BinaryStreamReader
Declaration
class BinaryStreamReader { /* full declaration omitted */ };
Description
Provides read only access to a subclass of `BinaryStream`. Provides bounds checking and helpers for writing certain common data types such as null-terminated strings, integers in various flavors of endianness, etc. Can be subclassed to provide reading of custom datatypes, although no are overridable.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:31
Method Overview
- public BinaryStreamReader(llvm::BinaryStreamRef Ref)
- public BinaryStreamReader(llvm::BinaryStream & Stream)
- public BinaryStreamReader(ArrayRef<uint8_t> Data, llvm::support::endianness Endian)
- public BinaryStreamReader(llvm::StringRef Data, llvm::support::endianness Endian)
- public BinaryStreamReader(const llvm::BinaryStreamReader & Other)
- public BinaryStreamReader()
- public uint32_t bytesRemaining() const
- public bool empty() const
- public uint32_t getLength() const
- public uint32_t getOffset() const
- public llvm::Error padToAlignment(uint32_t Align)
- public uint8_t peek() const
- public template <typename T>llvm::Error readArray(FixedStreamArray<T> & Array, uint32_t NumItems)
- public template <typename T, typename U>llvm::Error readArray(VarStreamArray<T, U> & Array, uint32_t Size, uint32_t Skew = 0)
- public template <typename T>llvm::Error readArray(ArrayRef<T> & Array, uint32_t NumElements)
- public llvm::Error readBytes(ArrayRef<uint8_t> & Buffer, uint32_t Size)
- public llvm::Error readCString(llvm::StringRef & Dest)
- public template <typename T>llvm::Error readEnum(T & Dest)
- public llvm::Error readFixedString(llvm::StringRef & Dest, uint32_t Length)
- public template <typename T>llvm::Error readInteger(T & Dest)
- public llvm::Error readLongestContiguousChunk(ArrayRef<uint8_t> & Buffer)
- public template <typename T>llvm::Error readObject(const T *& Dest)
- public llvm::Error readSLEB128(int64_t & Dest)
- public llvm::Error readStreamRef(llvm::BinaryStreamRef & Ref, uint32_t Length)
- public llvm::Error readStreamRef(llvm::BinaryStreamRef & Ref)
- public llvm::Error readSubstream(llvm::BinarySubstreamRef & Ref, uint32_t Length)
- public llvm::Error readULEB128(uint64_t & Dest)
- public llvm::Error readWideString(ArrayRef<llvm::UTF16> & Dest)
- public void setOffset(uint32_t Off)
- public llvm::Error skip(uint32_t Amount)
- public std::pair<BinaryStreamReader, BinaryStreamReader> split(uint32_t Offset) const
- public virtual ~BinaryStreamReader()
Methods
¶BinaryStreamReader(llvm::BinaryStreamRef Ref)
BinaryStreamReader(llvm::BinaryStreamRef Ref)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:34
Parameters
¶BinaryStreamReader(llvm::BinaryStream& Stream)
BinaryStreamReader(llvm::BinaryStream& Stream)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:35
Parameters
- llvm::BinaryStream& Stream
¶BinaryStreamReader(
ArrayRef<uint8_t> Data,
llvm::support::endianness Endian)
BinaryStreamReader(
ArrayRef<uint8_t> Data,
llvm::support::endianness Endian)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:36
Parameters
- ArrayRef<uint8_t> Data
- llvm::support::endianness Endian
¶BinaryStreamReader(
llvm::StringRef Data,
llvm::support::endianness Endian)
BinaryStreamReader(
llvm::StringRef Data,
llvm::support::endianness Endian)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:38
Parameters
- llvm::StringRef Data
- llvm::support::endianness Endian
¶BinaryStreamReader(
const llvm::BinaryStreamReader& Other)
BinaryStreamReader(
const llvm::BinaryStreamReader& Other)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:40
Parameters
- const llvm::BinaryStreamReader& Other
¶BinaryStreamReader()
BinaryStreamReader()
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:33
¶uint32_t bytesRemaining() const
uint32_t bytesRemaining() const
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:257
¶bool empty() const
bool empty() const
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:253
¶uint32_t getLength() const
uint32_t getLength() const
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:256
¶uint32_t getOffset() const
uint32_t getOffset() const
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:255
¶llvm::Error padToAlignment(uint32_t Align)
llvm::Error padToAlignment(uint32_t Align)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:271
Parameters
- uint32_t Align
¶uint8_t peek() const
uint8_t peek() const
Description
Examine the next byte of the underlying stream without advancing the stream's offset. If the stream is empty the behavior is undefined.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:269
Returns
the next byte in the stream.
¶template <typename T>
llvm::Error readArray(FixedStreamArray<T>& Array,
uint32_t NumItems)
template <typename T>
llvm::Error readArray(FixedStreamArray<T>& Array,
uint32_t NumItems)
Description
Read a FixedStreamArray of \p NumItems elements and store the result into\p Array. Updates the stream's offset to point after the newly read array. Never causes a copy (although iterating the elements of the FixedStreamArray may, depending upon the implementation of the underlying stream).
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:235
Templates
- T
Parameters
- FixedStreamArray<T>& Array
- uint32_t NumItems
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶template <typename T, typename U>
llvm::Error readArray(VarStreamArray<T, U>& Array,
uint32_t Size,
uint32_t Skew = 0)
template <typename T, typename U>
llvm::Error readArray(VarStreamArray<T, U>& Array,
uint32_t Size,
uint32_t Skew = 0)
Description
Read a VarStreamArray of size \p Size bytes and store the result into\p Array. Updates the stream's offset to point after the newly read array. Never causes a copy (although iterating the elements of the VarStreamArray may, depending upon the implementation of the underlying stream).
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:217
Templates
- T
- U
Parameters
- VarStreamArray<T, U>& Array
- uint32_t Size
- uint32_t Skew = 0
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶template <typename T>
llvm::Error readArray(ArrayRef<T>& Array,
uint32_t NumElements)
template <typename T>
llvm::Error readArray(ArrayRef<T>& Array,
uint32_t NumElements)
Description
Get a reference to a \p NumElements element array of objects of type T from the underlying stream as if by memcpy, and store the resulting array slice into \p array. It is up to the caller to ensure that objects of type T can be safely treated in this manner. Updates the stream's offset to point after the newly read object. Whether a copy occurs depends upon the implementation of the underlying stream.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:187
Templates
- T
Parameters
- ArrayRef<T>& Array
- uint32_t NumElements
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readBytes(ArrayRef<uint8_t>& Buffer,
uint32_t Size)
llvm::Error readBytes(ArrayRef<uint8_t>& Buffer,
uint32_t Size)
Description
Read \p Size bytes from the underlying stream at the current offset and and set \p Buffer to the resulting data slice. Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:66
Parameters
- ArrayRef<uint8_t>& Buffer
- uint32_t Size
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readCString(llvm::StringRef& Dest)
llvm::Error readCString(llvm::StringRef& Dest)
Description
Read a null terminated string from \p Dest. Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:117
Parameters
- llvm::StringRef& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶template <typename T>
llvm::Error readEnum(T& Dest)
template <typename T>
llvm::Error readEnum(T& Dest)
Description
Similar to readInteger.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:89
Templates
- T
Parameters
- T& Dest
¶llvm::Error readFixedString(llvm::StringRef& Dest,
uint32_t Length)
llvm::Error readFixedString(llvm::StringRef& Dest,
uint32_t Length)
Description
Read a \p Length byte string into \p Dest. Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:132
Parameters
- llvm::StringRef& Dest
- uint32_t Length
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶template <typename T>
llvm::Error readInteger(T& Dest)
template <typename T>
llvm::Error readInteger(T& Dest)
Description
Read an integer of the specified endianness into \p Dest and update the stream's offset. The data is always copied from the stream's underlying buffer into \p Dest. Updates the stream's offset to point after the newly read data.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:75
Templates
- T
Parameters
- T& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readLongestContiguousChunk(
ArrayRef<uint8_t>& Buffer)
llvm::Error readLongestContiguousChunk(
ArrayRef<uint8_t>& Buffer)
Description
Read as much as possible from the underlying string at the current offset without invoking a copy, and set \p Buffer to the resulting data slice. Updates the stream's offset to point after the newly read data.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:57
Parameters
- ArrayRef<uint8_t>& Buffer
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶template <typename T>
llvm::Error readObject(const T*& Dest)
template <typename T>
llvm::Error readObject(const T*& Dest)
Description
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the result into \p Dest. It is up to the caller to ensure that objects of type T can be safely treated in this manner. Updates the stream's offset to point after the newly read object. Whether a copy occurs depends upon the implementation of the underlying stream.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:169
Templates
- T
Parameters
- const T*& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readSLEB128(int64_t& Dest)
llvm::Error readSLEB128(int64_t& Dest)
Description
Read a signed LEB128 encoded value.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:109
Parameters
- int64_t& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readStreamRef(
llvm::BinaryStreamRef& Ref,
uint32_t Length)
llvm::Error readStreamRef(
llvm::BinaryStreamRef& Ref,
uint32_t Length)
Description
Read \p Length bytes from the underlying stream into \p Ref. This is equivalent to calling getUnderlyingStream().slice(Offset, Length). Updates the stream's offset to point after the newly read object. Never causes a copy.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:149
Parameters
- llvm::BinaryStreamRef& Ref
- uint32_t Length
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readStreamRef(
llvm::BinaryStreamRef& Ref)
llvm::Error readStreamRef(
llvm::BinaryStreamRef& Ref)
Description
Read the entire remainder of the underlying stream into \p Ref. This is equivalent to calling getUnderlyingStream().slice(Offset). Updates the stream's offset to point to the end of the stream. Never causes a copy.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:140
Parameters
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readSubstream(
llvm::BinarySubstreamRef& Ref,
uint32_t Length)
llvm::Error readSubstream(
llvm::BinarySubstreamRef& Ref,
uint32_t Length)
Description
Read \p Length bytes from the underlying stream into \p Ref. This is equivalent to calling getUnderlyingStream().slice(Offset, Length). Updates the stream's offset to point after the newly read object. Never causes a copy.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:158
Parameters
- llvm::BinarySubstreamRef& Ref
- uint32_t Length
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readULEB128(uint64_t& Dest)
llvm::Error readULEB128(uint64_t& Dest)
Description
Read an unsigned LEB128 encoded value.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:103
Parameters
- uint64_t& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶llvm::Error readWideString(
ArrayRef<llvm::UTF16>& Dest)
llvm::Error readWideString(
ArrayRef<llvm::UTF16>& Dest)
Description
Similar to readCString, however read a null-terminated UTF16 string instead.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:124
Parameters
- ArrayRef<llvm::UTF16>& Dest
Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.
¶void setOffset(uint32_t Off)
void setOffset(uint32_t Off)
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:254
Parameters
- uint32_t Off
¶llvm::Error skip(uint32_t Amount)
llvm::Error skip(uint32_t Amount)
Description
Advance the stream's offset by \p Amount bytes.
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:263
Parameters
- uint32_t Amount
Returns
a success error code if at least \p Amount bytes remain in the stream, otherwise returns an appropriate error code.
¶std::pair<BinaryStreamReader, BinaryStreamReader>
split(uint32_t Offset) const
std::pair<BinaryStreamReader, BinaryStreamReader>
split(uint32_t Offset) const
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:274
Parameters
- uint32_t Offset
¶virtual ~BinaryStreamReader()
virtual ~BinaryStreamReader()
Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:49