For years computer engineers have dealt with the problems associated with transfer of binary data between systems of different bit and byte order. Big-Endian (most significant first) vs. Little-Endian (least significant first). In this article, existing techniques are extended to develop a new, systematic method for coding Ada record component representations so that the same declaration may be used to define an input/output object of a communications link (or "flat" file) to achieve complete endian independence. The uniqueness of this approach is that rather than dealing with byte swapping at the lowest level where the fields of the most nested record components are defined, a single, simple byte-swap is done at the outermost level of the multi-field object. This technique works for multi-layered, nested records as well as for records with fields that consume partial, contiguous bytes. It is especially well suited for implementation where endian independence has not been anticipated in the design. The only special case is that of array components which require a simple pre/post fix-up. Some potential pitfalls and compiler issues are discussed.
/lp/association-for-computing-machinery/wholesale-byte-reversal-of-the-outermost-ada-record-object-to-achieve-l2cgrxVEZI