This function is bit compatible withFArchive::SerializeIntPacked. It is more efficient as only a few bytes are written and the base version is best suited for writing many bytes. This version can be made more efficient and take less bits when we can break backward compatibility. The last byte will only need 4 bits so we're currently wasting 4 bits. Another way to pack could be to store 2 bits first in order to indicate how many bytes are needed. That would eliminate all shifting and masking to reconstruct the bytes. The downside is that values less than 2^14 will waste 1-2 bits compared to the below algorithm.