Example for C (for structures not using enums nor bitfields, because are compiler-dependant, and avoiding architecture-dependant types like e.g. size_t/ssize_t) :
if (islittleendian() && sizeof(mystruct) == REFSIZE_mystruct)
memcpy(buffer, mystruct, sizeof(mystruct));
else
conversion_mystruct(buffer, mystruct);
(so you can avoid slow serialization in most platforms)
if (islittleendian() && sizeof(mystruct) == REFSIZE_mystruct)
else (so you can avoid slow serialization in most platforms)