5#ifndef WPINET_UV_BUFFER_H_
6#define WPINET_UV_BUFFER_H_
11#include <initializer_list>
36 :
Buffer{reinterpret_cast<const char*>(arr.
data()), arr.size()} {}
39 len =
static_cast<decltype(
len)
>(len_);
41 Buffer(
const char* base_,
size_t len_) {
42 base =
const_cast<char*
>(base_);
43 len =
static_cast<decltype(
len)
>(len_);
45 Buffer(uint8_t* base_,
size_t len_) {
46 base =
reinterpret_cast<char*
>(base_);
47 len =
static_cast<decltype(
len)
>(len_);
49 Buffer(
const uint8_t* base_,
size_t len_) {
50 base =
reinterpret_cast<char*
>(
const_cast<uint8_t*
>(base_));
51 len =
static_cast<decltype(
len)
>(len_);
57 std::span<const uint8_t>
bytes()
const {
58 return {
reinterpret_cast<const uint8_t*
>(
base),
len};
60 std::span<uint8_t>
bytes() {
return {
reinterpret_cast<uint8_t*
>(
base),
len}; }
62 operator std::span<const char>()
const {
return data(); }
63 operator std::span<char>() {
return data(); }
69 std::memcpy(buf.
base,
in.data(),
in.size());
75 std::memcpy(buf.
base,
in.data(),
in.size());
111template <
size_t DEPTH = 4>
128 if (m_pool.empty()) {
131 auto buf = m_pool.back();
148 for (
auto& buf : bufs) {
149 m_pool.emplace_back(buf.Move());
157 for (
auto& buf : m_pool) {
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1202
Data buffer.
Definition: Buffer.h:23
std::span< char > data()
Definition: Buffer.h:55
std::span< const char > data() const
Definition: Buffer.h:54
Buffer()
Definition: Buffer.h:25
Buffer(std::string_view str)
Definition: Buffer.h:33
void Deallocate()
Definition: Buffer.h:85
Buffer(const uv_buf_t &oth)
Definition: Buffer.h:29
Buffer Dup() const
Definition: Buffer.h:79
std::span< const uint8_t > bytes() const
Definition: Buffer.h:57
Buffer(const char *base_, size_t len_)
Definition: Buffer.h:41
Buffer(uint8_t *base_, size_t len_)
Definition: Buffer.h:45
static Buffer Allocate(size_t size)
Definition: Buffer.h:65
std::span< uint8_t > bytes()
Definition: Buffer.h:60
Buffer(const uint8_t *base_, size_t len_)
Definition: Buffer.h:49
Buffer(std::span< const uint8_t > arr)
Definition: Buffer.h:35
static Buffer Dup(std::string_view in)
Definition: Buffer.h:67
static Buffer Dup(std::span< const uint8_t > in)
Definition: Buffer.h:73
Buffer Move()
Definition: Buffer.h:91
Buffer(char *base_, size_t len_)
Definition: Buffer.h:37
friend void swap(Buffer &a, Buffer &b)
Definition: Buffer.h:98
A simple pool allocator for Buffers.
Definition: Buffer.h:112
Buffer operator()()
Allocate a buffer.
Definition: Buffer.h:140
SimpleBufferPool(size_t size=4096)
Constructor.
Definition: Buffer.h:118
SimpleBufferPool & operator=(const SimpleBufferPool &other)=delete
size_t Remaining() const
Get number of buffers left in the pool before a new buffer will be allocated from the heap.
Definition: Buffer.h:167
void Release(std::span< Buffer > bufs)
Release allocated buffers back into the pool.
Definition: Buffer.h:147
void Clear()
Clear the pool, releasing all buffers.
Definition: Buffer.h:156
SimpleBufferPool(const SimpleBufferPool &other)=delete
Buffer Allocate()
Allocate a buffer.
Definition: Buffer.h:127
~SimpleBufferPool()
Definition: Buffer.h:119
basic_string_view< char > string_view
Definition: core.h:501
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.h:5219
Definition: WebSocket.h:27
It should be possible to cast uv_buf_t[] to WSABUF[] see http://msdn.microsoft.com/en-us/library/ms74...
Definition: unix.h:112
size_t len
Definition: unix.h:114
char * base
Definition: unix.h:113