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:29

Member Variables

private llvm::BinaryStreamRef Stream
private uint64_t Offset = 0

Method Overview

Methods

BinaryStreamReader(llvm::BinaryStreamRef Ref)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:32

Parameters

llvm::BinaryStreamRef Ref

BinaryStreamReader(llvm::BinaryStream& Stream)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:33

Parameters

llvm::BinaryStream& Stream

BinaryStreamReader(
    ArrayRef<uint8_t> Data,
    llvm::support::endianness Endian)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:34

Parameters

ArrayRef<uint8_t> Data
llvm::support::endianness Endian

BinaryStreamReader(
    llvm::StringRef Data,
    llvm::support::endianness Endian)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:36

Parameters

llvm::StringRef Data
llvm::support::endianness Endian

BinaryStreamReader(
    const llvm::BinaryStreamReader& Other)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:38

Parameters

const llvm::BinaryStreamReader& Other

BinaryStreamReader()

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:31

uint64_t bytesRemaining() const

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:250

bool empty() const

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:246

uint64_t getLength() const

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:249

uint64_t getOffset() const

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:248

llvm::Error padToAlignment(uint32_t Align)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:264

Parameters

uint32_t Align

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:262

Returns

the next byte in the stream.

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:228

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)

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:210

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)

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:180

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)

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:59

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)

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:110

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)

Description

Similar to readInteger.

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:82

Templates

T

Parameters

T& Dest

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:125

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)

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:68

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)

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:50

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)

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:162

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)

Description

Read a signed LEB128 encoded value.

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:102

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)

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:142

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)

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:133

Parameters

llvm::BinaryStreamRef& Ref

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)

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:151

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)

Description

Read an unsigned LEB128 encoded value.

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:96

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)

Description

Similar to readCString, however read a null-terminated UTF16 string instead.

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:117

Parameters

ArrayRef<llvm::UTF16>& Dest

Returns

a success error code if the data was successfully read, otherwise returns an appropriate error code.

void setOffset(uint64_t Off)

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:247

Parameters

uint64_t Off

llvm::Error skip(uint64_t Amount)

Description

Advance the stream's offset by \p Amount bytes.

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:256

Parameters

uint64_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(uint64_t Offset) const

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:267

Parameters

uint64_t Offset

virtual ~BinaryStreamReader()

Declared at: llvm/include/llvm/Support/BinaryStreamReader.h:42