11 #ifndef PQXX_H_BINARYSTRING
12 #define PQXX_H_BINARYSTRING
14 #include "pqxx/compiler-public.hxx"
15 #include "pqxx/internal/compiler-internal-pre.hxx"
19 #include <string_view>
21 #include "pqxx/result.hxx"
22 #include "pqxx/strconv.hxx"
27 template<>
struct string_traits<binarystring>;
60 using value_type = std::char_traits<char_type>::char_type;
76 [[deprecated(
"Use std::byte for binary data.")]]
explicit binarystring(
83 [[deprecated(
"Use std::byte for binary data.")]]
explicit binarystring(
87 [[deprecated(
"Use std::byte for binary data.")]]
binarystring(
88 void const *, std::size_t);
92 std::shared_ptr<value_type> ptr,
size_type size) :
93 m_buf{std::move(ptr)}, m_size{size}
100 [[nodiscard]]
bool empty() const noexcept {
return size() == 0; }
110 return *(data() + m_size - 1);
132 [[nodiscard]] PQXX_PURE
bool operator==(
binarystring const &)
const noexcept;
135 return not operator==(rhs);
150 [[nodiscard]]
char const *
get() const noexcept
152 return reinterpret_cast<char const *
>(m_buf.get());
156 [[nodiscard]] std::string_view
view() const noexcept
158 return std::string_view(get(), size());
167 [[nodiscard]] std::string str()
const;
170 std::shared_ptr<value_type> m_buf;
196 auto const value_end{
into_buf(begin, end, value)};
197 return zview{begin, value_end - begin - 1};
203 if (
static_cast<std::size_t
>(end - begin) < budget)
205 "Not enough buffer space to escape binary data."};
207 return begin + budget;
212 #include "pqxx/internal/ignore-deprecated-pre.hxx"
214 std::shared_ptr<unsigned char> buf{
215 new unsigned char[size], [](
unsigned char const *x) {
delete[] x; }};
218 #include "pqxx/internal/ignore-deprecated-post.hxx"
223 #include "pqxx/internal/compiler-internal-post.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:152
constexpr std::size_t size_esc_bin(std::size_t binary_bytes) noexcept
Compute buffer size needed to escape binary data for use as a BYTEA.
Definition: util.hxx:269
void esc_bin(std::string_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:122
constexpr std::size_t size_unesc_bin(std::size_t escaped_bytes) noexcept
Compute binary size from the size of its escaped version.
Definition: util.hxx:278
Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:57
char const * get() const noexcept
Raw character buffer (no terminating zero is added).
Definition: binarystring.hxx:150
const_reverse_iterator crend() const
Definition: binarystring.hxx:122
const_reverse_iterator rbegin() const
Definition: binarystring.hxx:113
bool operator!=(binarystring const &rhs) const noexcept
Definition: binarystring.hxx:133
const_pointer const_iterator
Definition: binarystring.hxx:65
const_iterator end() const noexcept
Definition: binarystring.hxx:104
const_iterator begin() const noexcept
Definition: binarystring.hxx:102
std::char_traits< char_type >::char_type value_type
Definition: binarystring.hxx:60
value_type const & const_reference
Definition: binarystring.hxx:63
long difference_type
Definition: binarystring.hxx:62
value_type const * data() const noexcept
Unescaped field contents.
Definition: binarystring.hxx:125
binarystring(std::shared_ptr< value_type > ptr, size_type size)
Efficiently wrap a buffer of binary data in a binarystring.
Definition: binarystring.hxx:91
const_reverse_iterator crbegin() const
Definition: binarystring.hxx:117
std::size_t size_type
Definition: binarystring.hxx:61
const_reference front() const noexcept
Definition: binarystring.hxx:107
const_reference back() const noexcept
Definition: binarystring.hxx:108
std::string_view view() const noexcept
Read contents as a std::string_view.
Definition: binarystring.hxx:156
bool empty() const noexcept
Definition: binarystring.hxx:100
const_reference operator[](size_type i) const noexcept
Definition: binarystring.hxx:127
const_iterator cend() const noexcept
Definition: binarystring.hxx:105
const_reverse_iterator rend() const
Definition: binarystring.hxx:118
size_type length() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:99
binarystring & operator=(binarystring const &)
unsigned char char_type
Definition: binarystring.hxx:59
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: binarystring.hxx:66
const_iterator cbegin() const noexcept
Definition: binarystring.hxx:103
binarystring(binarystring const &)=default
value_type const * const_pointer
Definition: binarystring.hxx:64
size_type size() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:97
static std::size_t size_buffer(binarystring const &value) noexcept
Definition: binarystring.hxx:189
static zview to_buf(char *begin, char *end, binarystring const &value)
Definition: binarystring.hxx:194
static binarystring from_string(std::string_view text)
Definition: binarystring.hxx:210
static char * into_buf(char *begin, char *end, binarystring const &value)
Definition: binarystring.hxx:200
Could not convert value to string: not enough buffer space.
Definition: except.hxx:186
Reference to a field in a result set.
Definition: field.hxx:34
Traits describing a type's "null value," if any.
Definition: strconv.hxx:87
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:109
Traits class for use in string conversions.
Definition: strconv.hxx:149
static std::size_t size_buffer(TYPE const &value) noexcept
Estimate how much buffer space is needed to represent value.
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:38