1
0
Fork 0
flightgear/src/MultiPlayer/tiny_xdr.cpp
ehofman 7311d05c87 Oliver Schroeder:
I have prepared a new patch for multiplayer, which fixes endianess issues with
multiplayer code. It's basically identical to the patch I sent before my
vacation, but contains minor fixes.

Multiplayer should now be working under all unix-like environments and windows
native. The basic trick is to let configure check for endianess of the host
system.

It will not work on system not using configure in the build process (excluding
windows), ie. possibly MACOS. For those system we should provide #ifdefs in
tiny_xdr.hpp.


Erik:
I've updated the patch to use the Plib utils package for endian swapping an
used a preprocessor directive to detect endianess.
2005-09-18 12:37:18 +00:00

163 lines
2.8 KiB
C++

//////////////////////////////////////////////////////////////////////
//
// Tiny XDR implementation for flightgear
// written by Oliver Schroeder
// released to the puiblic domain
//
// This implementation is not complete, but implements
// everything we need.
//
// For further reading on XDR read RFC 1832.
//
//////////////////////////////////////////////////////////////////////
#include <plib/ul.h>
#include "tiny_xdr.hpp"
/* XDR 8bit integers */
xdr_data_t
XDR_encode_int8 ( int8_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
xdr_data_t
XDR_encode_uint8 ( uint8_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
int8_t
XDR_decode_int8 ( xdr_data_t n_Val )
{
return (static_cast<int8_t> (SWAP32(n_Val)));
}
uint8_t
XDR_decode_uint8 ( xdr_data_t n_Val )
{
return (static_cast<uint8_t> (SWAP32(n_Val)));
}
/* XDR 16bit integers */
xdr_data_t
XDR_encode_int16 ( int16_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
xdr_data_t
XDR_encode_uint16 ( uint16_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
int16_t
XDR_decode_int16 ( xdr_data_t n_Val )
{
return (static_cast<int16_t> (SWAP32(n_Val)));
}
uint16_t
XDR_decode_uint16 ( xdr_data_t n_Val )
{
return (static_cast<uint16_t> (SWAP32(n_Val)));
}
/* XDR 32bit integers */
xdr_data_t
XDR_encode_int32 ( int32_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
xdr_data_t
XDR_encode_uint32 ( uint32_t n_Val )
{
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
int32_t
XDR_decode_int32 ( xdr_data_t n_Val )
{
return (static_cast<int32_t> (SWAP32(n_Val)));
}
uint32_t
XDR_decode_uint32 ( xdr_data_t n_Val )
{
return (static_cast<uint32_t> (SWAP32(n_Val)));
}
/* XDR 64bit integers */
xdr_data2_t
XDR_encode_int64 ( int64_t n_Val )
{
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
}
xdr_data2_t
XDR_encode_uint64 ( uint64_t n_Val )
{
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
}
int64_t
XDR_decode_int64 ( xdr_data2_t n_Val )
{
return (static_cast<int64_t> (SWAP64(n_Val)));
}
uint64_t
XDR_decode_uint64 ( xdr_data2_t n_Val )
{
return (static_cast<uint64_t> (SWAP64(n_Val)));
}
/* float */
xdr_data_t
XDR_encode_float ( float f_Val )
{
xdr_data_t* tmp;
tmp = (xdr_data_t*) &f_Val;
return (XDR_encode_int32 (*tmp));
}
float
XDR_decode_float ( xdr_data_t f_Val )
{
float* tmp;
xdr_data_t dummy;
dummy = XDR_decode_int32 (f_Val);
tmp = (float*) &dummy;
return (*tmp);
}
/* double */
xdr_data2_t
XDR_encode_double ( double d_Val )
{
xdr_data2_t* tmp;
tmp = (xdr_data2_t*) &d_Val;
return (XDR_encode_int64 (*tmp));
}
double
XDR_decode_double ( xdr_data2_t d_Val )
{
double* tmp;
xdr_data2_t dummy;
dummy = XDR_decode_int64 (d_Val);
tmp = (double*) &dummy;
return (*tmp);
}