Add StreamBuffer::open
This commit is contained in:
@@ -22,10 +22,10 @@
|
|||||||
|
|
||||||
enum class InvocationKind {
|
enum class InvocationKind {
|
||||||
INVALID,
|
INVALID,
|
||||||
LUA_CALL,
|
LUA_INVOKE,
|
||||||
|
LUA_PROBE,
|
||||||
LUA_EXPR,
|
LUA_EXPR,
|
||||||
LUA_SOURCE,
|
LUA_SOURCE,
|
||||||
LUA_PROBE,
|
|
||||||
FLUSH_PRINTS,
|
FLUSH_PRINTS,
|
||||||
TICK,
|
TICK,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -349,6 +349,14 @@ public:
|
|||||||
init(true, false, const_cast<char *>(data.data()), data.size());
|
init(true, false, const_cast<char *>(data.data()), data.size());
|
||||||
write_cursor_ = buf_hi_;
|
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.
|
// Destructor. Frees the buffer, if any.
|
||||||
//
|
//
|
||||||
@@ -420,19 +428,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Discard all data. Reset total read and write counts.
|
// 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() {
|
void clear() {
|
||||||
assert(owned_);
|
if (!owned_) {
|
||||||
if ((!fixed_size_) && (buf_lo_ != nullptr) && ((buf_hi_ - buf_lo_) > 100000)) {
|
open("");
|
||||||
CoreHandler::basebuffer_free(buf_lo_);
|
} else {
|
||||||
buf_lo_ = nullptr;
|
if ((!fixed_size_) && (buf_lo_ != nullptr) && ((buf_hi_ - buf_lo_) > 100000)) {
|
||||||
buf_hi_ = nullptr;
|
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.
|
// Write block of bytes into the buffer.
|
||||||
|
|||||||
Reference in New Issue
Block a user