1 #include "messagebuf.hxx"
\r
3 #include <netinet/in.h>
\r
5 unsigned char FGMPSMessageBuf::get(bool raw)
\r
7 if (pos >= buf.length())
\r
8 throw FGMPSDataException( "FGMPSMessageBuf: Read past end of buffer" );
\r
9 if (raw) return buf[pos++];
\r
10 if ((unsigned char)buf[pos] == 0xff) {
\r
12 return ((unsigned char)buf[pos++] ^ 0xff);
\r
17 void FGMPSMessageBuf::put(unsigned char byte, bool raw)
\r
20 if ((byte & 0xf0) == 0xf0) {
\r
28 void FGMPSMessageBuf::write1(void* data)
\r
30 put(*(unsigned char *)data);
\r
33 void FGMPSMessageBuf::write2(void* data)
\r
35 *((uint16_t*)tmp) = htons(*((uint16_t*)data));
\r
40 void FGMPSMessageBuf::write4(void* data)
\r
42 *((uint32_t*)tmp) = htonl(*((uint32_t*)data));
\r
49 void FGMPSMessageBuf::write8(void* data)
\r
51 *((uint32_t*)tmp+0) = htonl(*((uint32_t*)data+4));
\r
52 *((uint32_t*)tmp+4) = htonl(*((uint32_t*)data+0));
\r
63 void FGMPSMessageBuf::writef(float data)
\r
68 void FGMPSMessageBuf::writed(double data)
\r
73 void FGMPSMessageBuf::writes(string data)
\r
76 for (int i=0; i<data.length(); i++) put(data[i]);
\r
79 void* FGMPSMessageBuf::read1()
\r
85 void* FGMPSMessageBuf::read2()
\r
89 *((uint16_t*)tmp) = ntohs(*((uint16_t*)tmp));
\r
93 void* FGMPSMessageBuf::read4()
\r
99 *((uint32_t*)tmp) = ntohl(*((uint32_t*)tmp));
\r
103 void* FGMPSMessageBuf::read8()
\r
105 unsigned char res[32];
\r
115 *((uint32_t*)tmp+4) = ntohl(*((uint32_t*)res+0));
\r
116 *((uint32_t*)tmp+0) = ntohl(*((uint32_t*)res+4));
\r
120 float FGMPSMessageBuf::readf()
\r
122 return *((float*)read4());
\r
125 double FGMPSMessageBuf::readd()
\r
127 return *((double*)read8());
\r
130 string FGMPSMessageBuf::reads(size_t length)
\r
133 for (int i=0; i<length; i++) res += get();
\r