Use our own stdint.hxx implementation.
This commit is contained in:
parent
278b7d7544
commit
22423d0bab
8 changed files with 47 additions and 135 deletions
|
@ -1,7 +1,3 @@
|
|||
noinst_PROGRAMS = swap_test
|
||||
|
||||
swap_test_SOURCES = swap_test.cpp
|
||||
|
||||
noinst_LIBRARIES = libMultiPlayer.a
|
||||
|
||||
libMultiPlayer_a_SOURCES = multiplayrxmgr.cxx multiplayrxmgr.hxx multiplaytxmgr.cxx multiplaytxmgr.hxx mpplayer.cxx mpplayer.hxx mpmessages.hxx tiny_xdr.cpp tiny_xdr.hpp
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "tiny_xdr.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
uint32_t ui32 = 0x01234567;
|
||||
uint64_t ui64 = 0x0123456789ABCDEFLL;
|
||||
|
||||
printf("UI32: (normal) %x\nUI32: (swapped) %x\n\n", ui32, bswap_32(ui32) );
|
||||
printf("UI64: (normal) %llx\nUI64: (swapped) %llx\n\n", ui64, bswap_64(ui64) );
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -17,50 +17,50 @@
|
|||
|
||||
/* XDR 8bit integers */
|
||||
xdr_data_t
|
||||
XDR_encode_int8 ( int8_t n_Val )
|
||||
XDR_encode_int8 ( const int8_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
xdr_data_t
|
||||
XDR_encode_uint8 ( uint8_t n_Val )
|
||||
XDR_encode_uint8 ( const uint8_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
int8_t
|
||||
XDR_decode_int8 ( xdr_data_t n_Val )
|
||||
XDR_decode_int8 ( const xdr_data_t & n_Val )
|
||||
{
|
||||
return (static_cast<int8_t> (SWAP32(n_Val)));
|
||||
}
|
||||
|
||||
uint8_t
|
||||
XDR_decode_uint8 ( xdr_data_t n_Val )
|
||||
XDR_decode_uint8 ( const 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 )
|
||||
XDR_encode_int16 ( const int16_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
xdr_data_t
|
||||
XDR_encode_uint16 ( uint16_t n_Val )
|
||||
XDR_encode_uint16 ( const uint16_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
int16_t
|
||||
XDR_decode_int16 ( xdr_data_t n_Val )
|
||||
XDR_decode_int16 ( const xdr_data_t & n_Val )
|
||||
{
|
||||
return (static_cast<int16_t> (SWAP32(n_Val)));
|
||||
}
|
||||
|
||||
uint16_t
|
||||
XDR_decode_uint16 ( xdr_data_t n_Val )
|
||||
XDR_decode_uint16 ( const xdr_data_t & n_Val )
|
||||
{
|
||||
return (static_cast<uint16_t> (SWAP32(n_Val)));
|
||||
}
|
||||
|
@ -68,25 +68,25 @@ XDR_decode_uint16 ( xdr_data_t n_Val )
|
|||
|
||||
/* XDR 32bit integers */
|
||||
xdr_data_t
|
||||
XDR_encode_int32 ( int32_t n_Val )
|
||||
XDR_encode_int32 ( const int32_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
xdr_data_t
|
||||
XDR_encode_uint32 ( uint32_t n_Val )
|
||||
XDR_encode_uint32 ( const uint32_t & n_Val )
|
||||
{
|
||||
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
||||
}
|
||||
|
||||
int32_t
|
||||
XDR_decode_int32 ( xdr_data_t n_Val )
|
||||
XDR_decode_int32 ( const xdr_data_t & n_Val )
|
||||
{
|
||||
return (static_cast<int32_t> (SWAP32(n_Val)));
|
||||
}
|
||||
|
||||
uint32_t
|
||||
XDR_decode_uint32 ( xdr_data_t n_Val )
|
||||
XDR_decode_uint32 ( const xdr_data_t & n_Val )
|
||||
{
|
||||
return (static_cast<uint32_t> (SWAP32(n_Val)));
|
||||
}
|
||||
|
@ -94,25 +94,25 @@ XDR_decode_uint32 ( xdr_data_t n_Val )
|
|||
|
||||
/* XDR 64bit integers */
|
||||
xdr_data2_t
|
||||
XDR_encode_int64 ( int64_t n_Val )
|
||||
XDR_encode_int64 ( const int64_t & n_Val )
|
||||
{
|
||||
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
|
||||
}
|
||||
|
||||
xdr_data2_t
|
||||
XDR_encode_uint64 ( uint64_t n_Val )
|
||||
XDR_encode_uint64 ( const uint64_t & n_Val )
|
||||
{
|
||||
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
|
||||
}
|
||||
|
||||
int64_t
|
||||
XDR_decode_int64 ( xdr_data2_t n_Val )
|
||||
XDR_decode_int64 ( const xdr_data2_t & n_Val )
|
||||
{
|
||||
return (static_cast<int64_t> (SWAP64(n_Val)));
|
||||
}
|
||||
|
||||
uint64_t
|
||||
XDR_decode_uint64 ( xdr_data2_t n_Val )
|
||||
XDR_decode_uint64 ( const xdr_data2_t & n_Val )
|
||||
{
|
||||
return (static_cast<uint64_t> (SWAP64(n_Val)));
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ XDR_decode_uint64 ( xdr_data2_t n_Val )
|
|||
|
||||
/* float */
|
||||
xdr_data_t
|
||||
XDR_encode_float ( float f_Val )
|
||||
XDR_encode_float ( const float & f_Val )
|
||||
{
|
||||
xdr_data_t* tmp;
|
||||
|
||||
|
@ -129,7 +129,7 @@ XDR_encode_float ( float f_Val )
|
|||
}
|
||||
|
||||
float
|
||||
XDR_decode_float ( xdr_data_t f_Val )
|
||||
XDR_decode_float ( const xdr_data_t & f_Val )
|
||||
{
|
||||
float* tmp;
|
||||
xdr_data_t dummy;
|
||||
|
@ -141,7 +141,7 @@ XDR_decode_float ( xdr_data_t f_Val )
|
|||
|
||||
/* double */
|
||||
xdr_data2_t
|
||||
XDR_encode_double ( double d_Val )
|
||||
XDR_encode_double ( const double & d_Val )
|
||||
{
|
||||
xdr_data2_t* tmp;
|
||||
|
||||
|
@ -150,7 +150,7 @@ XDR_encode_double ( double d_Val )
|
|||
}
|
||||
|
||||
double
|
||||
XDR_decode_double ( xdr_data2_t d_Val )
|
||||
XDR_decode_double ( const xdr_data2_t & d_Val )
|
||||
{
|
||||
double* tmp;
|
||||
xdr_data2_t dummy;
|
||||
|
|
|
@ -20,62 +20,8 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#if defined HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <simgear/misc/stdint.hxx>
|
||||
|
||||
#include <plib/ul.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// There are many sick systems out there:
|
||||
//
|
||||
// check for sizeof(float) and sizeof(double)
|
||||
// if sizeof(float) != 4 this code must be patched
|
||||
// if sizeof(double) != 8 this code must be patched
|
||||
//
|
||||
// Those are comments I fetched out of glibc source:
|
||||
// - s390 is big-endian
|
||||
// - Sparc is big-endian, but v9 supports endian conversion
|
||||
// on loads/stores and GCC supports such a mode. Be prepared.
|
||||
// - The MIPS architecture has selectable endianness.
|
||||
// - x86_64 is little-endian.
|
||||
// - CRIS is little-endian.
|
||||
// - m68k is big-endian.
|
||||
// - Alpha is little-endian.
|
||||
// - PowerPC can be little or big endian.
|
||||
// - SH is bi-endian but with a big-endian FPU.
|
||||
// - hppa1.1 big-endian.
|
||||
// - ARM is (usually) little-endian but with a big-endian FPU.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
inline uint32_t bswap_32(unsigned int b) {
|
||||
unsigned x = b;
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
|
||||
#if (SIZEOF_LONG_INT == 8)
|
||||
inline uint64_t bswap_64(unsigned long int b) {
|
||||
uint64_t x = b;
|
||||
x = ((x >> 8) & 0x00FF00FF00FF00FFLL) | ((x << 8) & 0xFF00FF00FF00FF00LL);
|
||||
x = ((x >> 16) & 0x0000FFFF0000FFFFLL) | ((x << 16) & 0xFFFF0000FFFF0000LL);
|
||||
x = (x >> 32) | (x << 32);
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
inline uint64_t bswap_64(unsigned long long int b) {
|
||||
union {
|
||||
uint64_t ll;
|
||||
uint32_t l[2];
|
||||
} w, r;
|
||||
w.ll = b;
|
||||
r.l[0] = bswap_32 (w.l[1]);
|
||||
r.l[1] = bswap_32 (w.l[0]);
|
||||
return r.ll;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
# define SWAP32(arg) arg
|
||||
|
@ -83,8 +29,8 @@ inline uint64_t bswap_64(unsigned long long int b) {
|
|||
# define LOW 0
|
||||
# define HIGH 1
|
||||
#else
|
||||
# define SWAP32(arg) bswap_32(arg)
|
||||
# define SWAP64(arg) bswap_64(arg)
|
||||
# define SWAP32(arg) sg_bswap_32(arg)
|
||||
# define SWAP64(arg) sg_bswap_64(arg)
|
||||
# define LOW 1
|
||||
# define HIGH 0
|
||||
#endif
|
||||
|
@ -95,28 +41,28 @@ typedef uint32_t xdr_data_t; /* 4 Bytes */
|
|||
typedef uint64_t xdr_data2_t; /* 8 Bytes */
|
||||
|
||||
/* XDR 8bit integers */
|
||||
xdr_data_t XDR_encode_int8 ( int8_t n_Val );
|
||||
xdr_data_t XDR_encode_uint8 ( uint8_t n_Val );
|
||||
int8_t XDR_decode_int8 ( xdr_data_t n_Val );
|
||||
uint8_t XDR_decode_uint8 ( xdr_data_t n_Val );
|
||||
xdr_data_t XDR_encode_int8 ( const int8_t & n_Val );
|
||||
xdr_data_t XDR_encode_uint8 ( const uint8_t & n_Val );
|
||||
int8_t XDR_decode_int8 ( const xdr_data_t & n_Val );
|
||||
uint8_t XDR_decode_uint8 ( const xdr_data_t & n_Val );
|
||||
|
||||
/* XDR 16bit integers */
|
||||
xdr_data_t XDR_encode_int16 ( int16_t n_Val );
|
||||
xdr_data_t XDR_encode_uint16 ( uint16_t n_Val );
|
||||
int16_t XDR_decode_int16 ( xdr_data_t n_Val );
|
||||
uint16_t XDR_decode_uint16 ( xdr_data_t n_Val );
|
||||
xdr_data_t XDR_encode_int16 ( const int16_t & n_Val );
|
||||
xdr_data_t XDR_encode_uint16 ( const uint16_t & n_Val );
|
||||
int16_t XDR_decode_int16 ( const xdr_data_t & n_Val );
|
||||
uint16_t XDR_decode_uint16 ( const xdr_data_t & n_Val );
|
||||
|
||||
/* XDR 32bit integers */
|
||||
xdr_data_t XDR_encode_int32 ( int32_t n_Val );
|
||||
xdr_data_t XDR_encode_uint32 ( const uint32_t n_Val );
|
||||
int32_t XDR_decode_int32 ( xdr_data_t n_Val );
|
||||
uint32_t XDR_decode_uint32 ( const xdr_data_t n_Val );
|
||||
xdr_data_t XDR_encode_int32 ( const int32_t & n_Val );
|
||||
xdr_data_t XDR_encode_uint32 ( const uint32_t & n_Val );
|
||||
int32_t XDR_decode_int32 ( const xdr_data_t & n_Val );
|
||||
uint32_t XDR_decode_uint32 ( const xdr_data_t & n_Val );
|
||||
|
||||
/* XDR 64bit integers */
|
||||
xdr_data2_t XDR_encode_int64 ( int64_t n_Val );
|
||||
xdr_data2_t XDR_encode_uint64 ( uint64_t n_Val );
|
||||
int64_t XDR_decode_int64 ( xdr_data2_t n_Val );
|
||||
uint64_t XDR_decode_uint64 ( xdr_data2_t n_Val );
|
||||
xdr_data2_t XDR_encode_int64 ( const int64_t & n_Val );
|
||||
xdr_data2_t XDR_encode_uint64 ( const uint64_t & n_Val );
|
||||
int64_t XDR_decode_int64 ( const xdr_data2_t & n_Val );
|
||||
uint64_t XDR_decode_uint64 ( const xdr_data2_t & n_Val );
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -131,11 +77,11 @@ uint64_t XDR_decode_uint64 ( xdr_data2_t n_Val );
|
|||
//
|
||||
//////////////////////////////////////////////////
|
||||
/* float */
|
||||
xdr_data_t XDR_encode_float ( float f_Val );
|
||||
float XDR_decode_float ( xdr_data_t f_Val );
|
||||
xdr_data_t XDR_encode_float ( const float & f_Val );
|
||||
float XDR_decode_float ( const xdr_data_t & f_Val );
|
||||
|
||||
/* double */
|
||||
xdr_data2_t XDR_encode_double ( double d_Val );
|
||||
double XDR_decode_double ( xdr_data2_t d_Val );
|
||||
xdr_data2_t XDR_encode_double ( const double & d_Val );
|
||||
double XDR_decode_double ( const xdr_data2_t & d_Val );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#ifndef _NET_CTRLS_HXX
|
||||
#define _NET_CTRLS_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/stdint.hxx>
|
||||
|
||||
// NOTE: this file defines an external interface structure. Due to
|
||||
// variability between platforms and architectures, we only used fixed
|
||||
|
@ -20,10 +20,6 @@
|
|||
// I am not aware of any platforms that don't use 4 bytes for float
|
||||
// and 8 bytes for double.
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
const uint32_t FG_NET_CTRLS_VERSION = 26;
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
|
||||
#include <time.h> // time_t
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/stdint.hxx>
|
||||
|
||||
// NOTE: this file defines an external interface structure. Due to
|
||||
// variability between platforms and architectures, we only used fixed
|
||||
|
@ -22,10 +22,6 @@
|
|||
// I am not aware of any platforms that don't use 4 bytes for float
|
||||
// and 8 bytes for double.
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
const uint32_t FG_NET_FDM_VERSION = 22;
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/stdint.hxx>
|
||||
|
||||
// NOTE: this file defines an external interface structure. Due to
|
||||
// variability between platforms and architectures, we only used fixed
|
||||
|
@ -25,10 +25,6 @@
|
|||
// I am not aware of any platforms that don't use 4 bytes for float
|
||||
// and 8 bytes for double.
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
const uint32_t FG_NET_FDM_MINI_VERSION = 2;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#ifndef _NET_GUI_HXX
|
||||
#define _NET_GUI_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/stdint.hxx>
|
||||
|
||||
// NOTE: this file defines an external interface structure. Due to
|
||||
// variability between platforms and architectures, we only used fixed
|
||||
|
@ -19,9 +19,6 @@
|
|||
// I am not aware of any platforms that don't use 4 bytes for float
|
||||
// and 8 bytes for double.
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
const uint32_t FG_NET_GUI_VERSION = 7;
|
||||
|
||||
|
|
Loading…
Reference in a new issue