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

@@ -75,7 +75,8 @@ void LuaSnap::serialize(StreamBuffer *sb) {
// Write dummy length, use eris to write data, then overwrite length.
sb->write_int64(0);
int64_t pos1 = sb->total_writes();
eris_dump(state_, sb->lua_writer, sb->lua_writer_ud());
eris_dump(state_, lua_writer_into_streambuffer, sb);
int64_t pos2 = sb->total_writes();
sb->overwrite_int64(pos1, pos2 - pos1);
lua_settop(state_, 0);
@@ -85,14 +86,15 @@ void LuaSnap::deserialize(StreamBuffer *sb) {
// Lua stack should be empty.
assert(lua_gettop(state_) == 0);
// Get the length of the eris dump.
int64_t len = sb->read_int64();
void *ud = sb->lua_reader_ud(len);
// Get the eris data and convert it to a LuaByteReader.
int64_t eris_len = sb->read_int64();
const char *eris_bytes = sb->read_bytes(eris_len);
LuaByteReader bytereader(eris_bytes, eris_len);
// Call eris with the permanents table and passing the snapshot as a lua_Reader.
lua_pushstring(state_, "unpersist");
lua_rawget(state_, LUA_REGISTRYINDEX);
eris_undump(state_, sb->lua_reader, ud);
eris_undump(state_, bytereader.lua_reader, bytereader.lua_reader_userdata());
// Set up a stack frame manually. Eris deserialization
// should have left permstable and regcopy on the stack.