Removing lua_reader and lua_writer from StreamBuffer
This commit is contained in:
@@ -15,8 +15,6 @@ void StreamBuffer::init(bool fixed, bool owned, char *buf, int64_t size) {
|
||||
pre_read_count_ = 0;
|
||||
owned_ = owned;
|
||||
fixed_size_ = fixed;
|
||||
lua_reader_data_ = 0;
|
||||
lua_reader_size_ = 0;
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer() {
|
||||
@@ -80,8 +78,6 @@ void StreamBuffer::make_space_slow(int64_t bytes) {
|
||||
|
||||
// Update some simple things.
|
||||
pre_read_count_ += (read_cursor_ - buf_lo_);
|
||||
lua_reader_data_ = 0;
|
||||
lua_reader_size_ = 0;
|
||||
|
||||
// Move the data to the beginning of the buffer, or to
|
||||
// the beginning of a new buffer.
|
||||
@@ -128,8 +124,6 @@ void StreamBuffer::clear() {
|
||||
read_cursor_ = buf_lo_;
|
||||
write_cursor_ = buf_lo_;
|
||||
pre_read_count_ = 0;
|
||||
lua_reader_data_ = 0;
|
||||
lua_reader_size_ = 0;
|
||||
}
|
||||
|
||||
eng::string StreamBuffer::readline() {
|
||||
@@ -341,34 +335,6 @@ util::HashValue StreamBuffer::hash() const {
|
||||
return std::make_pair(hash1, hash2);
|
||||
}
|
||||
|
||||
int StreamBuffer::lua_writer(lua_State *L, const void* p, size_t sz, void* ud) {
|
||||
StreamBuffer *sb = (StreamBuffer *)ud;
|
||||
memcpy(sb->make_space(sz), p, sz);
|
||||
sb->write_cursor_ += sz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *StreamBuffer::lua_writer_ud() {
|
||||
return this;
|
||||
}
|
||||
|
||||
const char *StreamBuffer::lua_reader(lua_State *L, void *ud, size_t *size) {
|
||||
StreamBuffer *sb = (StreamBuffer *)ud;
|
||||
*size = sb->lua_reader_size_;
|
||||
const char *data = sb->lua_reader_data_;
|
||||
// Next time the reader gets called, there's no data left.
|
||||
sb->lua_reader_data_ = 0;
|
||||
sb->lua_reader_size_ = 0;
|
||||
return data;
|
||||
}
|
||||
|
||||
void *StreamBuffer::lua_reader_ud(int64_t size) {
|
||||
const char *data = read_bytes(size);
|
||||
lua_reader_data_ = data;
|
||||
lua_reader_size_ = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
class StreamBufferWriter : public std::streambuf, public eng::opnew {
|
||||
private:
|
||||
StreamBuffer *target_;
|
||||
@@ -401,6 +367,13 @@ std::ostream &StreamBuffer::ostream() {
|
||||
return *ostream_;
|
||||
}
|
||||
|
||||
int lua_writer_into_streambuffer(lua_State *L, const void* bytes, size_t sz, void* sbv) {
|
||||
StreamBuffer *sb = (StreamBuffer *)sbv;
|
||||
memcpy(sb->make_space(sz), bytes, sz);
|
||||
sb->wrote_space(sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool streq(const char *str, const char *data) {
|
||||
int len = strlen(str);
|
||||
return memcmp(str, data, len) == 0;
|
||||
|
||||
Reference in New Issue
Block a user