From 6a97e6c9e78a226abf4342d9b72bf1cc0235d775 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Nov 2019 18:02:40 +0100 Subject: endian conversion for binary read --- ripser.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ripser.cpp') diff --git a/ripser.cpp b/ripser.cpp index 1ae62e1..59bd8ac 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -830,10 +830,15 @@ enum file_format { BINARY }; +static const uint16_t endian_check(0xff00); +static const bool is_big_endian = *reinterpret_cast(&endian_check); + template T read(std::istream& input_stream) { T result; - input_stream.read(reinterpret_cast(&result), sizeof(T)); - return result; // on little endian: boost::endian::little_to_native(result); + char* p = reinterpret_cast(&result); + input_stream.read(p, sizeof(T)); + if (is_big_endian) std::reverse(p, p + sizeof(T)); + return result; } compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { -- cgit v1.2.3