Skip to content

Instantly share code, notes, and snippets.

@markpapadakis
Created January 11, 2014 11:02
Show Gist options
  • Select an option

  • Save markpapadakis/8369526 to your computer and use it in GitHub Desktop.

Select an option

Save markpapadakis/8369526 to your computer and use it in GitHub Desktop.
// Previously
for (uint32_t i = 0; i != bookProps->columns.Size(); ++i)
{
const IColumn *const ic = bookProps->columns[i];
if (likely(!ic->IsSuperColumn()))
{
const Column *const c = (Column *)ic;
if (ic->name == "stitle")
bp->InsertSubstring("short_title", (char *)c->value.Data(), c->value.Length(), 11);
else if (ic->name == "bt")
bp->InsertSubstring("bind_type", (char *)c->value.Data(), c->value.Length(), 9);
else if (ic->name == "shape")
bp->InsertSubstring("shape", (char *)c->value.Data(), c->value.Length(), 5);
else if (ic->name == "series")
bp->InsertSubstring("series", (char *)c->value.Data(), c->value.Length(), 6);
else if (ic->name == "sseries")
bp->InsertSubstring("sseries", (char *)c->value.Data(), c->value.Length(), 7);
else if (ic->name == "otitle")
bp->InsertSubstring("orig_title", (char *)c->value.Data(), c->value.Length(), 10);
else if (ic->name == "d")
bp->InsertSubstring("descr", (char *)c->value.Data(), c->value.Length(), 5);
else if (ic->name == "isbn")
bp->InsertSubstring("isbn", (char *)c->value.Data(), c->value.Length(), 4);
else if (ic->name == "c")
bp->Insert("pubdt", *(uint32_t *)c->value.Data(), 5);
else if (ic->name == "pages")
bp->Insert("pages", *(uint32_t *)c->value.Data(), 5);
else if (ic->name == "aid")
authorId = *(uint32_t *)c->value.Data();
else if (ic->name == "pubid")
publisherId = *(uint32_t *)c->value.Data();
}
}
// Much better
bookProps->Map(bp,
{
{"stitle", "short_title"},
{"bt", "bind_type"},
{"shape", "shape"},
{"series", "series"},
{"sseries", "sseries"},
{"otitle", "orig_title"},
{"d", "descr"},
{"isbn", "isbn"},
{"c", "pubdt", [](const column_value &v) { return RPCValue::N(*(uint32_t *)v.Data()) }},
{"pages", "pages", [](const column_value &v) { return RPCValue::N(*(uint32_t *)v.Data()) }},
});
if (const Column *const c= (Column *)bookProps->GetColumn(_S("aid"))
aid = (uint32_t)c->value.Data();
if (const Column *const c= (Column *)bookProps->GetColumn(_S("pubid"))
publisherId = (uint32_t)c->value.Data();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment