Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created September 7, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/c05e72b35914306876f9c1c2292ef690 to your computer and use it in GitHub Desktop.
Save vinniefalco/c05e72b35914306876f9c1c2292ef690 to your computer and use it in GitHub Desktop.
static
void
serialize_impl(
string& s,
serializer& sr)
{
// serialize to a small buffer
// to avoid most reallocations
char buf[16384];
string_view sv;
sv = sr.read(buf);
if(sr.done())
{
s.append(sv);
return;
}
s.reserve(sv.size() * 2);
s.append(sv);
do
{
sv = sr.read(
s.data() + s.size(),
s.capacity() - s.size());
s.grow(sv.size());
}
while(! sr.done());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment