10 #include <initializer_list>
24 class Buffer :
public std::vector<unsigned char> {
26 typedef std::vector<unsigned char> Parent;
31 Buffer(std::initializer_list<unsigned char> lst) : Parent{lst} {}
34 explicit Buffer(Parent&& src) : Parent{std::move(src)} {}
37 template <
typename CharT>
38 explicit Buffer(
const std::basic_string<CharT>& src) {
43 Buffer(
const void* src, std::size_t nb) {
set(src, nb); }
46 template <
typename CharT>
47 void set(
const std::basic_string<CharT>& src) {
48 set(src.c_str(), src.length() *
sizeof(std::basic_string<CharT>::char_type));
52 void set(
const void* src, std::size_t nb) {
54 std::memcpy(data(), src, nb);
59 const auto c_str =
reinterpret_cast<const char*
>(data());
60 const auto nb = size();
67 const auto c_str =
reinterpret_cast<const wchar_t*
>(data());
68 const auto nb = size();
70 std::ostringstream oss;
71 oss <<
"Buffer size invalid at " << nb <<
" bytes";
72 throw std::runtime_error{oss.str()};
74 const auto nch = nb / 2;
80 const auto nb = size();
81 resize(nb + src.size());
82 std::memcpy(data() + nb, src.data(), src.size());
void set(const std::basic_string< CharT > &src)
void add(const Buffer &src)
Buffer(const std::basic_string< CharT > &src)
void set(const void *src, std::size_t nb)
Buffer(const void *src, std::size_t nb)
Buffer(std::initializer_list< unsigned char > lst)
std::wstring as_utf16() const
std::string as_utf8() const