34 size_t size()
const {
return _length; }
57 memset(_data, 0, len);
58 memcpy(_data, temp, _length);
69 size_t old_length = _length;
72 memset(_data + old_length, 0, _length - old_length);
81 bool empty() {
return _length == 0; }
92 if (p ==
nullptr || len == 0)
94 size_t old_length = _length;
96 memcpy(
data() + old_length, p, len);
101 return data()[index];
132 memcpy(
data(), beg, _length);
158 std::byte*
data() {
return _data; }
159 const std::byte*
data()
const {
return _data; }
161 size_t size()
const {
return _length; }
163 bool empty() {
return _length == 0; }
166 auto end() {
return _data + _length; }
181 _data = (std::byte*)beg;
187 _data = (std::byte*)beg;
192 _data = (std::byte*)b.
data();
214 return { (std::byte*)str.data(), str.size() };
219 return { (std::byte*)p, i };
223 return { (std::byte*)p, i };
227 return { buf.
data(), i };
229template<
typename T,
size_t N>
232 return { (std::byte*)v.data(), v.size() };
237 return { (std::byte*)v.data(), v.size() };
243 return { (std::byte*)&a, (std::byte*)(&a + 1) };
249 size_t size_old = buf.
size();
250 size_t size_app = buf_app.
size();
251 buf.
resize(size_old + size_app);
252 memcpy(buf.
data() + size_old, buf_app.
data(), size_app);
285 if (
sizeof(
T) != buf.
size())
290 memcpy(&a, buf.
data(),
sizeof(
T));
Buffer & operator=(const Buffer &b)
void reserve(size_t size)
Buffer(const std::byte *beg, const std::byte *end)
std::byte _ssoData[BUFFER_SSO_SIZE]
std::byte & operator[](size_t index)
const std::byte * data() const
void append(void *p, size_t len)
BufferView(const std::byte *beg, const std::byte *end)
BufferView(const Buffer &b)
BufferView(const std::byte *beg, size_t len)
std::byte & operator[](size_t index)
const std::byte * data() const
void BufferCast(BufferView buf, T &a)
从16进制字符串创建array
Buffer CreateBufferHex(std::string_view str)
从16进制字符串创建buffer
Buffer CreateBuffer(BufferView buf)
创建副本
constexpr size_t BUFFER_SSO_SIZE
void BufferAppend(Buffer &buf, BufferView buf_app)
追加数据
BufferView CreateBufferView(const Buffer &buf)
创建buffer视图(右值不能默认转换)