1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-04-18 17:24:03 +03:00
mvfst/quic/common/BufAccessor.cpp
Hani Damlaj 00e67c1bf9 mvfst License Header Update
Reviewed By: lnicco

Differential Revision: D33587012

fbshipit-source-id: 972eb440f0156c9c04aa6e8787561b18295c1a97
2022-01-18 13:56:12 -08:00

34 lines
913 B
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <quic/common/BufAccessor.h>
namespace quic {
SimpleBufAccessor::SimpleBufAccessor(size_t capacity)
: buf_(folly::IOBuf::create(capacity)), capacity_(buf_->capacity()) {}
Buf SimpleBufAccessor::obtain() {
Buf ret;
buf_.swap(ret);
return ret;
}
void SimpleBufAccessor::release(Buf buf) {
CHECK(!buf_) << "Can't override existing buf";
CHECK(buf) << "Invalid Buf being released";
CHECK_EQ(buf->capacity(), capacity_)
<< "Buf has wrong capacity, capacit_=" << capacity_
<< ", buf capacity=" << buf->capacity();
CHECK(!buf->isChained()) << "Reject chained buf";
buf_ = std::move(buf);
}
bool SimpleBufAccessor::ownsBuffer() const {
return (buf_ != nullptr);
}
} // namespace quic