Skip to content

Commit 40ee64c

Browse files
authored
Merge pull request #140 from tgaldes/master
Add support for Buffer construction via raw arrays
2 parents 3ffb0f1 + 74acf65 commit 40ee64c

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
@@ -141,6 +141,21 @@ class CPPKAFKA_API Buffer {
141141
template <typename T, size_t N>
142142
Buffer(T(&&data)[N]) = delete;
143143

144+
/**
145+
* Constructs a buffer from a raw array
146+
*
147+
* \param data The the array to be used as input
148+
*/
149+
template <typename T, size_t N>
150+
Buffer(const T(&data)[N])
151+
: data_(reinterpret_cast<const DataType*>(&data[0])), size_(sizeof(T) * N) {
152+
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
153+
}
154+
155+
// Don't allow construction from temporary raw arrays
156+
template <typename T, size_t N>
157+
Buffer(const T(&&data)[N]) = delete;
158+
144159
/**
145160
* \brief Construct a buffer from a const string ref
146161
*

0 commit comments

Comments
 (0)