File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include < cstdint>
4+
35// Cross-platform byte swap utilities
46// MSVC uses _byteswap_*, GCC/Clang use __builtin_bswap*
7+ // Only unsigned overloads to avoid ambiguity with size_t on different platforms
58
69#ifdef _MSC_VER
710#include < cstdlib> // for _byteswap_*
811
912inline uint16_t bswap16 (uint16_t value) { return _byteswap_ushort (value); }
10- inline int16_t bswap16 (int16_t value ) { return static_cast < int16_t > (_byteswap_ushort (static_cast < uint16_t > (value ))); }
1113inline uint32_t bswap32 (uint32_t value) { return _byteswap_ulong (value); }
12- inline int32_t bswap32 (int32_t value ) { return static_cast < int32_t > (_byteswap_ulong (static_cast < uint32_t > (value ))); }
1314inline uint64_t bswap64 (uint64_t value) { return _byteswap_uint64 (value); }
14- inline int64_t bswap64 (int64_t value ) { return static_cast < int64_t > (_byteswap_uint64 (static_cast < uint64_t > (value ))); }
1515
1616#else
1717// GCC/Clang
1818
1919inline uint16_t bswap16 (uint16_t value) { return __builtin_bswap16 (value); }
20- inline int16_t bswap16 (int16_t value ) { return static_cast < int16_t > (__builtin_bswap16 (static_cast < uint16_t > (value ))); }
2120inline uint32_t bswap32 (uint32_t value) { return __builtin_bswap32 (value); }
22- inline int32_t bswap32 (int32_t value ) { return static_cast < int32_t > (__builtin_bswap32 (static_cast < uint32_t > (value ))); }
2321inline uint64_t bswap64 (uint64_t value) { return __builtin_bswap64 (value); }
24- inline int64_t bswap64 (int64_t value ) { return static_cast < int64_t > (__builtin_bswap64 (static_cast < uint64_t > (value ))); }
2522
2623#endif
Original file line number Diff line number Diff line change @@ -167,8 +167,8 @@ void DataStreamGenerator::generateSyntheticData(std::vector<uint8_t>& buffer) {
167167
168168 // Write header (network byte order = big endian)
169169 AmpDataPacketHeader header;
170- header.ampID = bswap64 (state.ampId );
171- header.length = bswap64 (dataSize);
170+ header.ampID = bswap64 (static_cast < uint64_t >( state.ampId ) );
171+ header.length = bswap64 (static_cast < uint64_t >( dataSize) );
172172 std::memcpy (buffer.data (), &header, sizeof (header));
173173
174174 // Generate sample packets
@@ -187,8 +187,8 @@ void DataStreamGenerator::generateSyntheticData(std::vector<uint8_t>& buffer) {
187187
188188 // Write header
189189 AmpDataPacketHeader header;
190- header.ampID = bswap64 (state.ampId );
191- header.length = bswap64 (dataSize);
190+ header.ampID = bswap64 (static_cast < uint64_t >( state.ampId ) );
191+ header.length = bswap64 (static_cast < uint64_t >( dataSize) );
192192 std::memcpy (buffer.data (), &header, sizeof (header));
193193
194194 // Generate sample packets
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ void ECIHandler::handleNTPReturnSynch(std::shared_ptr<asio::ip::tcp::socket> soc
209209 // Send back 8-byte NTP time (simplified - just use our sync time)
210210 int64_t ntpTime = syncTime_;
211211 if (bigEndian_) {
212- ntpTime = bswap64 (ntpTime);
212+ ntpTime = static_cast < int64_t >( bswap64 (static_cast < uint64_t >( ntpTime)) );
213213 }
214214 asio::write (*socket, asio::buffer (&ntpTime, 8 ));
215215}
You can’t perform that action at this time.
0 commit comments