Use static_assert for consistency check.

* Rather than only checking at runtime only in DEBUG builds,
use static assert for a compile time check.
Make sure we copy from buffer to buffer with the same sizes.