summaryrefslogtreecommitdiff
path: root/i/simulotron/src/gs/gs_transmitter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/gs/gs_transmitter.cc')
-rw-r--r--i/simulotron/src/gs/gs_transmitter.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/i/simulotron/src/gs/gs_transmitter.cc b/i/simulotron/src/gs/gs_transmitter.cc
index a72f812..e9b6648 100644
--- a/i/simulotron/src/gs/gs_transmitter.cc
+++ b/i/simulotron/src/gs/gs_transmitter.cc
@@ -36,24 +36,26 @@ GSTransmitter::GSTransmitter(SocketClient & socket)
int
GSTransmitter::getGS(GSMessage & gsm)
{
+ ///BUG Pas portable le code, suppose des int à 4 octect
unsigned int size = 0;
std::string strRead (socket_.read ());
strBrut_ += strRead;
- size = static_cast<int> (strRead[0]) << 24
- | static_cast<int> (strRead[1]) << 16
- | static_cast<int> (strRead[2]) << 8
- | static_cast<int> (strRead[3]);
+ size = static_cast<int> (strBrut_[0]) << 24
+ | static_cast<int> (strBrut_[1]) << 16
+ | static_cast<int> (strBrut_[2]) << 8
+ | static_cast<int> (strBrut_[3]);
if(size > strBrut_.size() - 4)
return -1;
- strRead = strBrut_.substr (4, size -1);
- strBrut_.erase (4, size - 1);
- gsm.writeGS (strRead.c_str (), size);
+ strRead = strBrut_.substr (4, size);
+ strBrut_.erase (0, size + 4);
+ gsm.writeGS (strRead.data (), size);
return 0;
}
void
GSTransmitter::putGS(const GSMessage & gsm)
{
+ ///BUG Pas portable le code, suppose des int à 4 octect
std::string gs(gsm.getGS ());
char bsize[4];
int size = gs.size();
@@ -61,6 +63,6 @@ GSTransmitter::putGS(const GSMessage & gsm)
bsize[1] = static_cast<char> (size >> 16);
bsize[2] = static_cast<char> (size >> 8);
bsize[3] = static_cast<char> (size);
- gs.insert(0, bsize);
- socket_.write (gsm.getGS ());
+ gs.insert(0, bsize, 4);
+ socket_.write (gs);
}