15 #ifndef THRILL_NET_FIXED_BUFFER_BUILDER_HEADER 16 #define THRILL_NET_FIXED_BUFFER_BUILDER_HEADER 37 template <
size_t Capacity>
43 using Byte =
unsigned char;
55 std::array<Byte, Capacity>
data_;
98 assert(n <= Capacity);
106 return std::string(reinterpret_cast<const char*>(data_.data()), size_);
116 assert(size_ + len <= Capacity);
118 const Byte* cdata =
reinterpret_cast<const Byte*
>(
data);
119 std::copy(cdata, cdata + len, data_.data() +
size_);
128 return Append(s.data(), s.size());
133 template <
typename Type>
136 "You only want to Put() POD types as raw values.");
138 assert(size_ +
sizeof(
Type) <= Capacity);
140 *
reinterpret_cast<Type*
>(data_.data() +
size_) = item;
141 size_ +=
sizeof(
Type);
148 return Put<uint8_t>(
data);
153 template <
typename Type>
155 return Put<Type>(item);
165 {
return data_.data(); }
168 {
return data_.data(); }
172 {
return data_.data() +
size_; }
175 {
return data_.data() +
size_; }
180 return *(
begin() + i);
191 #endif // !THRILL_NET_FIXED_BUFFER_BUILDER_HEADER FixedBufferBuilder & Clear()
Clears the memory contents, does not deallocate the memory.
FixedBufferBuilder & Append(const void *data, size_t len)
Append a memory range to the buffer.
unsigned char Byte
type used to store the bytes
size_t capacity() const
Return the currently allocated buffer capacity.
iterator end()
return mutable iterator beyond last element
size_t size_
Size of valid data.
Byte * data()
Return a writeable pointer to the currently kept memory area.
std::string ToString() const
Explicit conversion to std::string (copies memory of course).
size_t size() const
Return the currently used length in bytes.
FixedBufferBuilder & set_size(size_t n)
iterator begin()
return mutable iterator to first element
Byte * iterator
simple pointer iterators
Byte & reference
simple pointer references
const Byte & const_reference
simple pointer references
FixedBufferBuilder & AppendString(const std::string &s)
Represents a FIXED length area of memory, which can be modified by appending integral data types via ...
reference operator[](size_t i)
return the i-th position of the vector
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
std::array< Byte, Capacity > data_
Allocated buffer.
FixedBufferBuilder & Put(const Type &item)
const_iterator begin() const
return constant iterator to first element
FixedBufferBuilder & PutByte(Byte data)
Put a single byte to the buffer (used via CRTP from ItemWriterToolsBase)
const_iterator end() const
return constant iterator beyond last element
const Byte * data() const
Return a pointer to the currently kept memory area.
const Byte * const_iterator
simple pointer iterators
FixedBufferBuilder & PutRaw(const Type &item)