10 #ifndef LLVM_SUPPORT_BINARYSTREAMWRITER_H
11 #define LLVM_SUPPORT_BINARYSTREAMWRITER_H
22 #include <type_traits>
66 static_assert(std::is_integral<T>::value,
67 "Cannot call writeInteger with non-integral value!");
68 uint8_t Buffer[
sizeof(
T)];
69 llvm::support::endian::write<T, llvm::support::unaligned>(
76 static_assert(std::is_enum<T>::value,
77 "Cannot call writeEnum with non-Enum type");
79 using U =
typename std::underlying_type<T>::type;
80 return writeInteger<U>(
static_cast<U
>(Num));
123 static_assert(!std::is_pointer<T>::value,
124 "writeObject should not be used with pointers, to write "
125 "the pointed-to value dereference the pointer before calling "
141 if (Array.
size() > UINT32_MAX /
sizeof(
T))
142 return make_error<BinaryStreamError>(
147 Array.
size() *
sizeof(
T)));
154 template <
typename T,
typename U>
168 std::pair<BinaryStreamWriter, BinaryStreamWriter>
split(
uint32_t Off)
const;
183 #endif // LLVM_SUPPORT_BINARYSTREAMWRITER_H
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
BinaryStreamWriter()=default
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
uint32_t getLength() const
BinaryStreamWriter(const BinaryStreamWriter &Other)
BinaryStreamWriter & operator=(const BinaryStreamWriter &Other)
uint32_t getOffset() const
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
Error writeArray(VarStreamArray< T, U > Array)
Writes all data from the array Array to the underlying stream.
Error writeFixedString(StringRef Str)
Write the the string Str to the underlying stream without a null terminator.
virtual uint32_t getLength()=0
Return the number of bytes of data in this stream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
size_t size() const
size - Get the array size.
virtual llvm::support::endianness getEndian() const =0
Error writeArray(FixedStreamArray< T > Array)
Writes all elements from the array Array to the underlying stream.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
WritableBinaryStreamRef Stream
Provides write only access to a subclass of WritableBinaryStream.
bool empty() const
empty - Check if the array is empty.
Error writeInteger(T Value)
Write the the integer Value to the underlying stream in the specified endianness. ...
Error writeCString(StringRef Str)
Write the the string Str to the underlying stream followed by a null terminator.
static ErrorSuccess success()
Create a success value.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
virtual ~BinaryStreamWriter()
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Error writeEnum(T Num)
Similar to writeInteger.
void setOffset(uint32_t Off)
uint32_t bytesRemaining() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Error padToAlignment(uint32_t Align)
BinaryStreamRef getUnderlyingStream() const
std::pair< BinaryStreamWriter, BinaryStreamWriter > split(uint32_t Off) const
Splits the Writer into two Writers at a given offset.
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
BinaryStreamRef getUnderlyingStream() const
A BinaryStream which can be read from as well as written to.