Byte-swap integers to support big endian architectures #61
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #47
libbgcode always processes binary data in a byte-wise fashion. This breaks when the host architecture is not little endian, because binary Gcode requires data to be in little endian byte order.
This PR separates byte-wise and integer I/O and checksum functions, so the latter can be byte-swapped before they are processed. All occurrences of integer data access that I could find have been replaced with calls to the new functions.
The PR also removes the redundant
write_to_fileandread_from_filefunctions incore.cppandbinarize.cppand moves them to a single implementation incore_impl.hpp.The patched code has been tested on amd64 (little endian) and sparc64 (big endian). All unit tests pass.
Possible further improvements:
store_integer_leandload_integerwith boost::endian, which might make the code easier to understand and more optimal in some cases, although modern compilers can figure out what the functions do and replace them with optimized built-ins in some cases.