Removing lua_reader and lua_writer from StreamBuffer

This commit is contained in:
2023-10-18 14:03:05 -04:00
parent b4c2d21aee
commit 67b0265092
5 changed files with 56 additions and 61 deletions

View File

@@ -266,6 +266,17 @@ public:
// Get the total number of bytes ever written to this buffer.
int64_t total_writes() const;
// Make the specified amount of space in the buffer for writing.
// Return a pointer to the space.
char *make_space(int64_t bytes) {
int64_t available = buf_hi_ - write_cursor_;
if (available < bytes) make_space_slow(bytes);
return write_cursor_;
}
// Used after calling make_space then filling the space.
void wrote_space(int64_t bytes);
// Amount of data inside the buffer.
int64_t fill() const;
@@ -374,14 +385,6 @@ public:
// Calculate a noncryptographic but good hash of what's in the buffer.
util::HashValue hash() const;
// Use the stream buffer as a lua_Writer.
static int lua_writer(lua_State *L, const void* p, size_t sz, void* ud);
void *lua_writer_ud();
// Use the stream buffer as a lua_Reader.
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();
@@ -407,26 +410,13 @@ private:
// True if we're not allowed to expand this buffer.
bool fixed_size_;
// Lua reader return value.
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);
// Make the specified amount of space in the buffer for writing.
// Return a pointer to the space.
char *make_space(int64_t bytes) {
int64_t available = buf_hi_ - write_cursor_;
if (available < bytes) make_space_slow(bytes);
return write_cursor_;
}
void make_space_slow(int64_t bytes);
void wrote_space(int64_t bytes);
// Implementation for the overwrite_int functions.
char *get_overwrite(int64_t size, int64_t write_count_after);
@@ -437,4 +427,7 @@ private:
friend int lfn_unittests_streambuffer(lua_State *L);
};
// Use a streambuffer as a lua_writer.
int lua_writer_into_streambuffer(lua_State *L, const void* bytes, size_t sz, void* sb);
#endif // STREAMBUFFER_HPP