Skip to content

Commit 93eb0f2

Browse files
committed
Fix protocol incompatibility introduced in 6e0070c.
Also: Assert that endianness is little or big, don't use a Boost macro name.
1 parent 6a98f83 commit 93eb0f2

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/data_receiver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void data_receiver::data_thread() {
171171
server_stream << "LSL:streamfeed/" << proposed_protocol_version << " "
172172
<< conn_.current_uid() << "\r\n";
173173
// transmit request parameters
174-
server_stream << "Native-Byte-Order: " << BOOST_BYTE_ORDER << "\r\n";
174+
server_stream << "Native-Byte-Order: " << LSL_BYTE_ORDER << "\r\n";
175175
server_stream << "Endian-Performance: "
176176
<< std::floor(measure_endian_performance()) << "\r\n";
177177
server_stream << "Has-IEEE754-Floats: "
@@ -228,7 +228,7 @@ void data_receiver::data_thread() {
228228
// get the header information
229229
if (type == "byte-order") {
230230
use_byte_order = std::stoi(rest);
231-
if (use_byte_order == 2134 && BOOST_BYTE_ORDER != 2134 &&
231+
if (use_byte_order == 2134 && LSL_BYTE_ORDER != 2134 &&
232232
format_sizes[conn_.type_info().channel_format()] >= 8)
233233
throw std::runtime_error(
234234
"The byte order conversion requested by the other party is "

src/sample.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ void load_raw(std::streambuf &sb, void *address, std::size_t count) {
136136
template <typename T> T load_value(std::streambuf &sb, int use_byte_order) {
137137
T tmp;
138138
load_raw(sb, &tmp, sizeof(T));
139-
if (sizeof(T) > 1 && use_byte_order != BOOST_BYTE_ORDER) endian_reverse_inplace(tmp);
139+
if (sizeof(T) > 1 && use_byte_order != LSL_BYTE_ORDER) endian_reverse_inplace(tmp);
140140
return tmp;
141141
}
142142

143143
/// Save a value to a stream buffer with correct endian treatment.
144144
template <typename T> void save_value(std::streambuf &sb, T v, int use_byte_order) {
145-
if (use_byte_order != BOOST_BYTE_ORDER) endian_reverse_inplace(v);
145+
if (use_byte_order != LSL_BYTE_ORDER) endian_reverse_inplace(v);
146146
save_raw(sb, &v, sizeof(T));
147147
}
148148

@@ -181,7 +181,7 @@ void sample::save_streambuf(
181181
}
182182
} else {
183183
// write numeric data in binary
184-
if (use_byte_order == BOOST_BYTE_ORDER || format_sizes[format_] == 1) {
184+
if (use_byte_order == LSL_BYTE_ORDER || format_sizes[format_] == 1) {
185185
save_raw(sb, &data_, datasize());
186186
} else {
187187
memcpy(scratchpad, &data_, datasize());
@@ -227,7 +227,7 @@ void sample::load_streambuf(
227227
} else {
228228
// read numeric channel data
229229
load_raw(sb, &data_, datasize());
230-
if (use_byte_order != BOOST_BYTE_ORDER && format_sizes[format_] > 1) convert_endian(&data_);
230+
if (use_byte_order != LSL_BYTE_ORDER && format_sizes[format_] > 1) convert_endian(&data_);
231231
if (suppress_subnormals && format_float[format_]) {
232232
if (format_ == cft_float32) {
233233
for (uint32_t *p = (uint32_t *)&data_, *e = p + num_channels_; p < e; p++)

src/sample.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <string>
1313
#include <type_traits>
1414

15-
const int BOOST_BYTE_ORDER =
16-
lslboost::endian::order::native == lslboost::endian::order::little ? 4321 : 1234;
15+
// Determine target byte order / endianness
16+
using byteorder = lslboost::endian::order;
17+
static_assert(byteorder::native == byteorder::little || byteorder::native == byteorder::big, "Unsupported byteorder");
18+
const int LSL_BYTE_ORDER = (byteorder::native == byteorder::little) ? 1234 : 4321;
1719

1820
// Boost.Endian has no functions to reverse floats, so we pretend they're ints of the same size.
1921
template <typename T> inline void endian_reverse_inplace(T &t) {

src/tcp_server.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class client_session : public std::enable_shared_from_this<client_session> {
123123
int data_protocol_version_{100};
124124
/// byte order to use (0=portable, 1234=little endian, 4321=big endian, 2134=PDP endian,
125125
/// unsupported)
126-
int use_byte_order_{BOOST_BYTE_ORDER};
126+
int use_byte_order_{LSL_BYTE_ORDER};
127127
/// our chunk granularity
128128
int chunk_granularity_{0};
129129
/// maximum number of samples buffered
@@ -425,20 +425,20 @@ void client_session::handle_read_feedparams(
425425
data_protocol_version_ = 100;
426426
if (data_protocol_version_ >= 110) {
427427
// decide on the byte order if conflicting
428-
if (BOOST_BYTE_ORDER != client_byte_order) {
428+
if (LSL_BYTE_ORDER != client_byte_order) {
429429
if (client_byte_order == 2134 && client_value_size >= 8) {
430430
// since we have no implementation for this byte order conversion let
431431
// the client do it
432-
use_byte_order_ = BOOST_BYTE_ORDER;
432+
use_byte_order_ = LSL_BYTE_ORDER;
433433
} else {
434434
// let the faster party perform the endian conversion
435435
use_byte_order_ = (client_value_size <= 1 || (measure_endian_performance() >
436436
client_endian_performance))
437437
? client_byte_order
438-
: BOOST_BYTE_ORDER;
438+
: LSL_BYTE_ORDER;
439439
}
440440
} else
441-
use_byte_order_ = BOOST_BYTE_ORDER;
441+
use_byte_order_ = LSL_BYTE_ORDER;
442442
// determine if subnormal suppression needs to be enabled
443443
client_suppress_subnormals =
444444
(format_subnormal[format] && !client_supports_subnormals);

0 commit comments

Comments
 (0)