Avoid aliasing problems by using special buf endian handling functions wrapping memcpy