Add StreamBuffer::open
This commit is contained in:
@@ -349,6 +349,14 @@ public:
|
||||
init(true, false, const_cast<char *>(data.data()), data.size());
|
||||
write_cursor_ = buf_hi_;
|
||||
}
|
||||
|
||||
// Modify an existing streambuffer to read from an external block of bytes.
|
||||
//
|
||||
void open(std::string_view data) {
|
||||
if (owned_ && (buf_lo_ != 0)) CoreHandler::basebuffer_free(buf_lo_);
|
||||
init(true, false, const_cast<char *>(data.data()), data.size());
|
||||
write_cursor_ = buf_hi_;
|
||||
}
|
||||
|
||||
// Destructor. Frees the buffer, if any.
|
||||
//
|
||||
@@ -420,19 +428,21 @@ public:
|
||||
}
|
||||
|
||||
// Discard all data. Reset total read and write counts.
|
||||
// Releases the allocated buffer, if any.
|
||||
// May release the allocated buffer, if it is large.
|
||||
//
|
||||
void clear() {
|
||||
assert(owned_);
|
||||
if ((!fixed_size_) && (buf_lo_ != nullptr) && ((buf_hi_ - buf_lo_) > 100000)) {
|
||||
CoreHandler::basebuffer_free(buf_lo_);
|
||||
buf_lo_ = nullptr;
|
||||
buf_hi_ = nullptr;
|
||||
if (!owned_) {
|
||||
open("");
|
||||
} else {
|
||||
if ((!fixed_size_) && (buf_lo_ != nullptr) && ((buf_hi_ - buf_lo_) > 100000)) {
|
||||
CoreHandler::basebuffer_free(buf_lo_);
|
||||
buf_lo_ = nullptr;
|
||||
buf_hi_ = nullptr;
|
||||
}
|
||||
read_cursor_ = buf_lo_;
|
||||
write_cursor_ = buf_lo_;
|
||||
pre_read_count_ = 0;
|
||||
}
|
||||
owned_ = true;
|
||||
read_cursor_ = buf_lo_;
|
||||
write_cursor_ = buf_lo_;
|
||||
pre_read_count_ = 0;
|
||||
}
|
||||
|
||||
// Write block of bytes into the buffer.
|
||||
|
||||
Reference in New Issue
Block a user