Skip to content

Instantly share code, notes, and snippets.

@galik
Created October 4, 2018 19:31
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 galik/c3b075560fad9ea4bae9d9d06da4caa0 to your computer and use it in GitHub Desktop.
Save galik/c3b075560fad9ea4bae9d9d06da4caa0 to your computer and use it in GitHub Desktop.
It seems to me you should at least be able to avoid figuring out all the different buffer offsets and field types.
maybe something like this?
struct stuff_t
{
std::uint16_t a;
float b;
std::uint64_t c;
// ...
};
template<typename Field>
char const* copy_fild(Field& field, char const* pos)
{
std::copy(pos, pos + sizeof(field), (char*)&field);
return pos + sizeof(field);
}
char const* copy_stuff(stuff_t& st, char const* const buffer)
{
auto pos = buffer;
pos = copy_fild(st.a, pos);
pos = copy_fild(st.b, pos);
pos = copy_fild(st.c, pos);
// ...
return pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment