Add 'ostream' method to class StreamBuffer, and use it.

This commit is contained in:
2021-11-03 12:31:13 -04:00
parent 17a1155906
commit 7cbf40e3d6
5 changed files with 71 additions and 25 deletions

View File

@@ -239,7 +239,7 @@ public:
};
class StreamBuffer {
public:
public:
// Construct an empty buffer.
StreamBuffer();
@@ -387,6 +387,9 @@ public:
static const char *lua_reader(lua_State *L, void *data, size_t *size);
void *lua_reader_ud(int64_t bytes);
// Get an ostream that writes into the StreamBuffer.
std::ostream &ostream();
private:
// Start and end of the allocated block.
char *buf_lo_;
@@ -409,6 +412,9 @@ private:
const char *lua_reader_data_;
int64_t lua_reader_size_;
// The ostream. Only allocated on demand.
std::unique_ptr<std::ostream> ostream_;
// Initialize with a new buffer.
void init(bool fixed, bool owned, char *buf, int64_t size);