Skip to content

Conversation

@onitake
Copy link

@onitake onitake commented Dec 19, 2025

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_file and read_from_file functions in core.cpp and binarize.cpp and moves them to a single implementation in core_impl.hpp.

The patched code has been tested on amd64 (little endian) and sparc64 (big endian). All unit tests pass.

Possible further improvements:

  • Replace store_integer_le and load_integer with 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken on big-endian architectures

1 participant