LLVM  8.0.1
Public Member Functions | Protected Attributes | List of all members
llvm::BinaryStreamWriter Class Reference

Provides write only access to a subclass of WritableBinaryStream. More...

#include "llvm/Support/BinaryStreamWriter.h"

Collaboration diagram for llvm::BinaryStreamWriter:
Collaboration graph
[legend]

Public Member Functions

 BinaryStreamWriter ()=default
 
 BinaryStreamWriter (WritableBinaryStreamRef Ref)
 
 BinaryStreamWriter (WritableBinaryStream &Stream)
 
 BinaryStreamWriter (MutableArrayRef< uint8_t > Data, llvm::support::endianness Endian)
 
 BinaryStreamWriter (const BinaryStreamWriter &Other)
 
BinaryStreamWriteroperator= (const BinaryStreamWriter &Other)
 
virtual ~BinaryStreamWriter ()
 
Error writeBytes (ArrayRef< uint8_t > Buffer)
 Write the bytes specified in Buffer to the underlying stream. More...
 
template<typename T >
Error writeInteger (T Value)
 Write the integer Value to the underlying stream in the specified endianness. More...
 
template<typename T >
Error writeEnum (T Num)
 Similar to writeInteger. More...
 
Error writeCString (StringRef Str)
 Write the string Str to the underlying stream followed by a null terminator. More...
 
Error writeFixedString (StringRef Str)
 Write the string Str to the underlying stream without a null terminator. More...
 
Error writeStreamRef (BinaryStreamRef Ref)
 Efficiently reads all data from Ref, and writes it to this stream. More...
 
Error writeStreamRef (BinaryStreamRef Ref, uint32_t Size)
 Efficiently reads Size bytes from Ref, and writes it to this stream. More...
 
template<typename T >
Error writeObject (const T &Obj)
 Writes the object Obj to the underlying stream, as if by using memcpy. More...
 
template<typename T >
Error writeArray (ArrayRef< T > Array)
 Writes an array of objects of type T to the underlying stream, as if by using memcpy. More...
 
template<typename T , typename U >
Error writeArray (VarStreamArray< T, U > Array)
 Writes all data from the array Array to the underlying stream. More...
 
template<typename T >
Error writeArray (FixedStreamArray< T > Array)
 Writes all elements from the array Array to the underlying stream. More...
 
std::pair< BinaryStreamWriter, BinaryStreamWritersplit (uint32_t Off) const
 Splits the Writer into two Writers at a given offset. More...
 
void setOffset (uint32_t Off)
 
uint32_t getOffset () const
 
uint32_t getLength () const
 
uint32_t bytesRemaining () const
 
Error padToAlignment (uint32_t Align)
 

Protected Attributes

WritableBinaryStreamRef Stream
 
uint32_t Offset = 0
 

Detailed 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.

Definition at line 32 of file BinaryStreamWriter.h.

Constructor & Destructor Documentation

◆ BinaryStreamWriter() [1/5]

llvm::BinaryStreamWriter::BinaryStreamWriter ( )
default

◆ BinaryStreamWriter() [2/5]

BinaryStreamWriter::BinaryStreamWriter ( WritableBinaryStreamRef  Ref)
explicit

Definition at line 18 of file BinaryStreamWriter.cpp.

◆ BinaryStreamWriter() [3/5]

BinaryStreamWriter::BinaryStreamWriter ( WritableBinaryStream Stream)
explicit

Definition at line 21 of file BinaryStreamWriter.cpp.

◆ BinaryStreamWriter() [4/5]

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

Definition at line 24 of file BinaryStreamWriter.cpp.

◆ BinaryStreamWriter() [5/5]

llvm::BinaryStreamWriter::BinaryStreamWriter ( const BinaryStreamWriter Other)
inline

Definition at line 40 of file BinaryStreamWriter.h.

◆ ~BinaryStreamWriter()

virtual llvm::BinaryStreamWriter::~BinaryStreamWriter ( )
inlinevirtual

Definition at line 49 of file BinaryStreamWriter.h.

References writeBytes().

Member Function Documentation

◆ bytesRemaining()

uint32_t llvm::BinaryStreamWriter::bytesRemaining ( ) const
inline

◆ getLength()

uint32_t llvm::BinaryStreamWriter::getLength ( ) const
inline

◆ getOffset()

uint32_t llvm::BinaryStreamWriter::getOffset ( ) const
inline

◆ operator=()

BinaryStreamWriter& llvm::BinaryStreamWriter::operator= ( const BinaryStreamWriter Other)
inline

Definition at line 43 of file BinaryStreamWriter.h.

References Offset, and Stream.

◆ padToAlignment()

Error BinaryStreamWriter::padToAlignment ( uint32_t  Align)

◆ setOffset()

void llvm::BinaryStreamWriter::setOffset ( uint32_t  Off)
inline

◆ split()

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

◆ writeArray() [1/3]

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

◆ writeArray() [2/3]

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

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

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

Definition at line 155 of file BinaryStreamWriter.h.

References llvm::VarStreamArray< ValueType, Extractor >::getUnderlyingStream(), and writeStreamRef().

◆ writeArray() [3/3]

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

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

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

Definition at line 163 of file BinaryStreamWriter.h.

References llvm::FixedStreamArray< T >::getUnderlyingStream(), split(), and writeStreamRef().

◆ writeBytes()

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

◆ writeCString()

Error BinaryStreamWriter::writeCString ( StringRef  Str)

Write the string 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. Str need not be null terminated on input.

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

Definition at line 35 of file BinaryStreamWriter.cpp.

References llvm::Error::success(), writeFixedString(), and writeObject().

Referenced by llvm::pdb::DbiModuleDescriptorBuilder::commit(), llvm::pdb::DbiStreamBuilder::getSourceFileNameIndex(), llvm::codeview::CodeViewRecordIO::mapStringZ(), and writeEnum().

◆ writeEnum()

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

◆ writeFixedString()

Error BinaryStreamWriter::writeFixedString ( StringRef  Str)

Write the string Str to the underlying stream without a null terminator.

On success, updates the offset so that subsequent writes occur at the next unwritten position.

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

Definition at line 44 of file BinaryStreamWriter.cpp.

References llvm::arrayRefFromStringRef(), and writeBytes().

Referenced by llvm::pdb::NamedStreamMap::commit(), writeCString(), and writeEnum().

◆ writeInteger()

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

◆ writeObject()

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

◆ writeStreamRef() [1/2]

Error BinaryStreamWriter::writeStreamRef ( BinaryStreamRef  Ref)

Efficiently reads all data from 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.

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

Definition at line 49 of file BinaryStreamWriter.cpp.

References llvm::BinaryStreamRefBase< RefType, StreamType >::getLength().

Referenced by llvm::pdb::TpiStreamBuilder::commit(), llvm::codeview::DebugSubsectionRecordBuilder::commit(), llvm::pdb::DbiStreamBuilder::commit(), writeArray(), writeEnum(), and writeRecords().

◆ writeStreamRef() [2/2]

Error BinaryStreamWriter::writeStreamRef ( BinaryStreamRef  Ref,
uint32_t  Size 
)

Efficiently reads Size bytes from 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.

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

Definition at line 53 of file BinaryStreamWriter.cpp.

References llvm::BinaryStreamRefBase< RefType, StreamType >::slice(), llvm::Error::success(), and writeBytes().

Member Data Documentation

◆ Offset

uint32_t llvm::BinaryStreamWriter::Offset = 0
protected

Definition at line 178 of file BinaryStreamWriter.h.

Referenced by getOffset(), operator=(), padToAlignment(), setOffset(), split(), and writeBytes().

◆ Stream

WritableBinaryStreamRef llvm::BinaryStreamWriter::Stream
protected

Definition at line 177 of file BinaryStreamWriter.h.

Referenced by operator=(), split(), and writeBytes().


The documentation for this class was generated from the following files: