File tree Expand file tree Collapse file tree 2 files changed +10
-14
lines changed
Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,11 @@ void BridgeTransport::OnRecv(const uvw::data_event& event) {
8080
8181 char len_buf[4 ];
8282 recv_buf_.Peek (len_buf, 4 );
83- uint32_t size = LE32_TO_NATIVE (*reinterpret_cast <uint32_t *>(len_buf));
83+ uint32_t size = 0 ;
84+ size |= static_cast <uint32_t >(len_buf[0 ]) << 0 ;
85+ size |= static_cast <uint32_t >(len_buf[1 ]) << 8 ;
86+ size |= static_cast <uint32_t >(len_buf[2 ]) << 16 ;
87+ size |= static_cast <uint32_t >(len_buf[3 ]) << 24 ;
8488
8589 if (size > VRBRIDGE_MAX_MESSAGE_SIZE) {
8690 logger_->Log (" message size overflow" );
@@ -116,8 +120,12 @@ void BridgeTransport::SendBridgeMessage(const messages::ProtobufMessage& message
116120 uint32_t wrapped_size = size + 4 ;
117121
118122 auto message_buf = std::make_unique<char []>(wrapped_size);
119- *reinterpret_cast <uint32_t *>(message_buf.get ()) = NATIVE_TO_LE32 (wrapped_size);
123+ message_buf.get ()[0 ] = (wrapped_size >> 0 ) & 0xFF ;
124+ message_buf.get ()[1 ] = (wrapped_size >> 8 ) & 0xFF ;
125+ message_buf.get ()[2 ] = (wrapped_size >> 16 ) & 0xFF ;
126+ message_buf.get ()[3 ] = (wrapped_size >> 24 ) & 0xFF ;
120127 message.SerializeToArray (message_buf.get () + 4 , size);
128+
121129 if (!send_buf_.Push (message_buf.get (), wrapped_size)) {
122130 ResetConnection ();
123131 return ;
Original file line number Diff line number Diff line change 3131#include " CircularBuffer.hpp"
3232#include " ProtobufMessages.pb.h"
3333
34- #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
35- #define LE32_TO_NATIVE (x ) (x)
36- #else
37- #define LE32_TO_NATIVE (x ) ( \
38- ((uint32_t )(x) << 24 ) | \
39- (((uint32_t )(x) << 8 ) & 0x00FF0000 ) | \
40- (((uint32_t )(x) >> 8 ) & 0x0000FF00 ) | \
41- ((uint32_t )(x) >> 24 ) \
42- )
43- #endif
44- #define NATIVE_TO_LE32 LE32_TO_NATIVE
45-
4634#define VRBRIDGE_MAX_MESSAGE_SIZE 1024
4735#define VRBRIDGE_BUFFERS_SIZE 8192
4836
You can’t perform that action at this time.
0 commit comments