Skip to content

Commit 74acf65

Browse files
author
Tyler Galdes
committed
Add support for Buffer construction via raw arrays
1 parent 248d1b0 commit 74acf65

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/cppkafka/buffer.h

+15
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ class CPPKAFKA_API Buffer {
111111
template <typename T, size_t N>
112112
Buffer(std::array<T, N>&& data) = delete;
113113

114+
/**
115+
* Constructs a buffer from a raw array
116+
*
117+
* \param data The the array to be used as input
118+
*/
119+
template <typename T, size_t N>
120+
Buffer(const T(&data)[N])
121+
: data_(reinterpret_cast<const DataType*>(&data[0])), size_(sizeof(T) * N) {
122+
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
123+
}
124+
125+
// Don't allow construction from temporary raw arrays
126+
template <typename T, size_t N>
127+
Buffer(const T(&&data)[N]) = delete;
128+
114129
/**
115130
* \brief Construct a buffer from a const string ref
116131
*

0 commit comments

Comments
 (0)