class BinaryStreamWriter

Declaration

class BinaryStreamWriter { /* full declaration omitted */ };

Description

Provides write only access to a subclass of `WritableBinaryStream`. 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 and writing of custom datatypes, although no methods are overridable.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:30

Member Variables

protected llvm::WritableBinaryStreamRef Stream
protected uint64_t Offset = 0

Method Overview

Methods

BinaryStreamWriter(
    llvm::WritableBinaryStreamRef Ref)

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

Parameters

llvm::WritableBinaryStreamRef Ref

BinaryStreamWriter(
    llvm::WritableBinaryStream& Stream)

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

Parameters

llvm::WritableBinaryStream& Stream

BinaryStreamWriter(
    MutableArrayRef<uint8_t> Data,
    llvm::support::endianness Endian)

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:35

Parameters

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

BinaryStreamWriter(
    const llvm::BinaryStreamWriter& Other)

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

Parameters

const llvm::BinaryStreamWriter& Other

BinaryStreamWriter()

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

uint64_t bytesRemaining() const

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:180

uint64_t getLength() const

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:179

uint64_t getOffset() const

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:178

llvm::Error padToAlignment(uint32_t Align)

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:181

Parameters

uint32_t Align

void setOffset(uint64_t Off)

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:177

Parameters

uint64_t Off

std::pair<BinaryStreamWriter, BinaryStreamWriter>
split(uint64_t Off) const

Description

Splits the Writer into two Writers at a given offset.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:175

Parameters

uint64_t Off

template <typename T>
llvm::Error writeArray(FixedStreamArray<T> Array)

Description

Writes all elements from the array \p Array to the underlying stream.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:170

Templates

T

Parameters

FixedStreamArray<T> Array

Returns

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

template <typename T, typename U>
llvm::Error writeArray(VarStreamArray<T, U> Array)

Description

Writes all data from the array \p Array to the underlying stream.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:162

Templates

T
U

Parameters

VarStreamArray<T, U> Array

Returns

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

template <typename T>
llvm::Error writeArray(ArrayRef<T> Array)

Description

Writes an array of objects of type T to the underlying stream, as if by using memcpy. It is up to the caller to ensure that type of \p Obj can be safely copied in this fashion, as no checks are made to ensure that this is safe.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:145

Templates

T

Parameters

ArrayRef<T> Array

Returns

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

llvm::Error writeBytes(ArrayRef<uint8_t> Buffer)

Description

Write the bytes specified in \p Buffer to the underlying stream. On success, updates the offset so that subsequent writes will occur at the next unwritten position.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:50

Parameters

ArrayRef<uint8_t> Buffer

Returns

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

llvm::Error writeCString(llvm::StringRef Str)

Description

Write the string \p Str to the underlying stream followed by a null terminator. On success, updates the offset so that subsequent writes occur at the next unwritten position. \p Str need not be null terminated on input.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:97

Parameters

llvm::StringRef Str

Returns

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

template <typename T>
llvm::Error writeEnum(T Num)

Description

Similar to writeInteger

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:68

Templates

T

Parameters

T Num

llvm::Error writeFixedString(llvm::StringRef Str)

Description

Write the string \p Str to the underlying stream without a null terminator. On success, updates the offset so that subsequent writes occur at the next unwritten position.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:105

Parameters

llvm::StringRef Str

Returns

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

template <typename T>
llvm::Error writeInteger(T Value)

Description

Write the integer \p Value to the underlying stream in the specified endianness. On success, updates the offset so that subsequent writes occur at the next unwritten position.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:58

Templates

T

Parameters

T Value

Returns

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

template <typename T>
llvm::Error writeObject(const T& Obj)

Description

Writes the object \p Obj to the underlying stream, as if by using memcpy. It is up to the caller to ensure that type of \p Obj can be safely copied in this fashion, as no checks are made to ensure that this is safe.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:129

Templates

T

Parameters

const T& Obj

Returns

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

llvm::Error writeSLEB128(int64_t Value)

Description

Write the unsigned integer Value to the underlying stream using ULEB128 encoding.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:88

Parameters

int64_t Value

Returns

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

llvm::Error writeStreamRef(
    llvm::BinaryStreamRef Ref,
    uint64_t Size)

Description

Efficiently reads \p Size bytes from \p Ref, and writes it to this stream. This operation will not invoke any copies of the source data, regardless of the source stream's implementation.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:121

Parameters

llvm::BinaryStreamRef Ref
uint64_t Size

Returns

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

llvm::Error writeStreamRef(
    llvm::BinaryStreamRef Ref)

Description

Efficiently reads all data from \p Ref, and writes it to this stream. This operation will not invoke any copies of the source data, regardless of the source stream's implementation.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:113

Parameters

llvm::BinaryStreamRef Ref

Returns

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

llvm::Error writeULEB128(uint64_t Value)

Description

Write the unsigned integer Value to the underlying stream using ULEB128 encoding.

Declared at: llvm/include/llvm/Support/BinaryStreamWriter.h:81

Parameters

uint64_t Value

Returns

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

virtual ~BinaryStreamWriter()

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