14#include "llvm/Support/Endian.h"
15#include "llvm/Support/ErrorHandling.h"
23using namespace llvm::support::endian;
26 : m_data_sp(new
DataBufferHeap()), m_byte_order(endian::InlHostByteOrder()),
27 m_addr_size(sizeof(void *)) {}
31 : m_data_sp(new
DataBufferHeap(data, length)), m_byte_order(endian),
32 m_addr_size(addr_size) {}
36 m_addr_size(addr_size) {}
61 write16be(
m_data_sp->GetBytes() + offset, value);
63 write16le(
m_data_sp->GetBytes() + offset, value);
65 return offset +
sizeof(value);
73 write32be(
m_data_sp->GetBytes() + offset, value);
75 write32le(
m_data_sp->GetBytes() + offset, value);
77 return offset +
sizeof(value);
85 write64be(
m_data_sp->GetBytes() + offset, value);
87 write64le(
m_data_sp->GetBytes() + offset, value);
89 return offset +
sizeof(value);
98 return PutU8(offset, value);
100 return PutU16(offset, value);
102 return PutU32(offset, value);
104 return PutU64(offset, value);
106 llvm_unreachable(
"GetMax64 unhandled case!");
113 if (src ==
nullptr || src_len == 0)
117 memcpy(
m_data_sp->GetBytes() + offset, src, src_len);
118 return offset + src_len;
129 return PutData(offset, cstr, strlen(cstr) + 1);
134 m_data_sp->AppendData(&value,
sizeof(value));
138 uint32_t offset =
m_data_sp->GetByteSize();
144 uint32_t offset =
m_data_sp->GetByteSize();
150 uint32_t offset =
m_data_sp->GetByteSize();
164 llvm_unreachable(
"AppendAddress unhandled case!");
169 const char *bytes = data.data();
170 const size_t length = data.size();
171 if (bytes && length > 0)
176 const uint8_t *bytes = data.data();
177 const size_t length = data.size();
178 if (bytes && length > 0)
183 const char *bytes = data.data();
184 const size_t length = data.size();
188 if (length == 0 || bytes[length - 1] !=
'\0')
A subclass of DataBuffer that stores a data buffer on the heap.
DataEncoder()
Default constructor.
const lldb::ByteOrder m_byte_order
The byte order of the data we are encoding to.
uint32_t PutU8(uint32_t offset, uint8_t value)
Encode an unsigned integer at offset offset.
void AppendCString(llvm::StringRef data)
Append a C string to the end of the owned data.
uint32_t PutUnsigned(uint32_t offset, uint32_t byte_size, uint64_t value)
Encode an unsigned integer of size byte_size to offset.
uint32_t PutAddress(uint32_t offset, lldb::addr_t addr)
Encode an address in the existing buffer at offset bytes into the buffer.
llvm::ArrayRef< uint8_t > GetData() const
Get a access to the bytes that this references.
void AppendAddress(lldb::addr_t addr)
Append an address sized integer to the end of the owned data.
void AppendU32(uint32_t value)
uint32_t PutU64(uint32_t offset, uint64_t value)
uint32_t PutCString(uint32_t offset, const char *cstr)
Put a C string to offset.
std::shared_ptr< lldb_private::DataBufferHeap > m_data_sp
The shared pointer to data that can grow as data is added.
const uint8_t m_addr_size
The address size to use when encoding pointers or addresses.
bool ValidOffset(uint32_t offset) const
Test the validity of offset.
size_t GetByteSize() const
Get the number of bytes contained in this object.
uint32_t PutU32(uint32_t offset, uint32_t value)
void AppendU8(uint8_t value)
Append a unsigned integer to the end of the owned data.
void AppendData(llvm::StringRef data)
Append a bytes to the end of the owned data.
void AppendU16(uint16_t value)
void AppendU64(uint64_t value)
bool ValidOffsetForDataOfSize(uint32_t offset, uint32_t length) const
Test the availability of length bytes of data from offset.
uint32_t PutU16(uint32_t offset, uint16_t value)
uint32_t PutData(uint32_t offset, const void *src, uint32_t src_len)
Encode an arbitrary number of bytes.
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
ByteOrder
Byte ordering definitions.