Lots of work on debugging diff xmit

This commit is contained in:
2021-11-21 13:35:39 -05:00
parent 0881e33c6f
commit b19825aaca
23 changed files with 338 additions and 99 deletions

View File

@@ -64,8 +64,6 @@ void PrintBuffer::clear() {
}
}
static int first_line_len(const char *text, int len) {
for (int i = 0; i < len; i++) {
if (text[i] == '\n') return i;
@@ -157,11 +155,14 @@ void PrintBuffer::diff(const PrintBuffer &auth, StreamBuffer *sb) const {
}
}
void PrintBuffer::patch(StreamBuffer *sb) {
void PrintBuffer::patch(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "PrintBuffer::patch");
if (core_ == &shared_core) core_ = new PrintBufferCore;
int auth_first = sb->read_int32();
int auth_last = sb->read_int32();
core_->lines_.resize(core_->first_unchecked_ - core_->first_line_);
int nlines = auth_last - core_->first_unchecked_;
if (nlines > 0) DebugLine(dbc) << "PrintBuffer received " << nlines << " lines.";
for (int i = core_->first_unchecked_; i < auth_last; i++) {
core_->lines_.emplace_back(sb->read_string());
}
@@ -238,29 +239,29 @@ LuaDefine(unittests_printbuffer, "c") {
sb.clear();
pbm.add_string("foo\nbar\n", true);
pbs.diff(pbm, &sb);
pbs.patch(&sb);
pbs.patch(&sb, nullptr);
LuaAssertStrEq(L, pbs.debug_string(), "0,2:foo;bar;");
pbm.clear();
pbm.add_string("foo\nyow\nding\ndong\n", true);
pbs.diff(pbm, &sb);
pbs.patch(&sb);
pbs.patch(&sb, nullptr);
LuaAssertStrEq(L, pbs.debug_string(), "0,4:foo;bar;ding;dong;");
pbs.discard_upto(2);
LuaAssertStrEq(L, pbs.debug_string(), "2,4:ding;dong;");
pbs.diff(pbm, &sb);
pbs.patch(&sb);
pbs.patch(&sb, nullptr);
LuaAssertStrEq(L, pbs.debug_string(), "2,4:ding;dong;");
pbs.add_string("boy\nhowdy\n", false);
LuaAssertStrEq(L, pbs.debug_string(), "2,4:ding;dong;boy;howdy;");
pbs.diff(pbm, &sb);
pbs.patch(&sb);
pbs.patch(&sb, nullptr);
LuaAssertStrEq(L, pbs.debug_string(), "2,4:ding;dong;");
pbs.add_string("boy\nhowdy\nyeah\nbaby\nget\ndown\n", false);
LuaAssertStrEq(L, pbs.debug_string(), "2,4:ding;dong;boy;howdy;yeah;baby;get;down;");
pbs.discard_upto(5);
LuaAssertStrEq(L, pbs.debug_string(), "5,5:howdy;yeah;baby;get;down;");
pbs.diff(pbm, &sb);
pbs.patch(&sb);
pbs.patch(&sb, nullptr);
LuaAssertStrEq(L, pbs.debug_string(), "5,5:");