-unique_ptr<IOBuf> IOBuf::wrapBuffer(const void* buf, uint32_t capacity) {
- // We cast away the const-ness of the buffer here.
- // This is okay since IOBuf users must use unshare() to create a copy of
- // this buffer before writing to the buffer.
- uint8_t* bufPtr = static_cast<uint8_t*>(const_cast<void*>(buf));
- return unique_ptr<IOBuf>(new IOBuf(kExtUserSupplied, kFlagUserOwned,
- bufPtr, capacity,
- bufPtr, capacity,
- NULL));
+IOBuf::IOBuf(WrapBufferOp, const void* buf, uint64_t capacity)
+ : IOBuf(InternalConstructor(), 0,
+ // We cast away the const-ness of the buffer here.
+ // This is okay since IOBuf users must use unshare() to create a copy
+ // of this buffer before writing to the buffer.
+ static_cast<uint8_t*>(const_cast<void*>(buf)), capacity,
+ static_cast<uint8_t*>(const_cast<void*>(buf)), capacity) {
+}
+
+IOBuf::IOBuf(WrapBufferOp op, ByteRange br)
+ : IOBuf(op, br.data(), br.size()) {
+}
+
+unique_ptr<IOBuf> IOBuf::wrapBuffer(const void* buf, uint64_t capacity) {
+ return make_unique<IOBuf>(WRAP_BUFFER, buf, capacity);
+}
+
+IOBuf::IOBuf() noexcept {
+}
+
+IOBuf::IOBuf(IOBuf&& other) noexcept {
+ *this = std::move(other);
+}
+
+IOBuf::IOBuf(const IOBuf& other) {
+ other.cloneInto(*this);