| 1 |
////////////////////////////////////////////////////////////////////// |
| 2 |
// |
| 3 |
// Tiny XDR implementation for flightgear |
| 4 |
// written by Oliver Schroeder |
| 5 |
// released to the public domain |
| 6 |
// |
| 7 |
// This implementation is not complete, but implements |
| 8 |
// everything we need. |
| 9 |
// |
| 10 |
// For further reading on XDR read RFC 1832. |
| 11 |
// |
| 12 |
// NEW |
| 13 |
// |
| 14 |
////////////////////////////////////////////////////////////////////// |
| 15 |
|
| 16 |
#ifndef TINY_XDR_HEADER |
| 17 |
#define TINY_XDR_HEADER |
| 18 |
|
| 19 |
#if defined HAVE_CONFIG_H |
| 20 |
# include <config.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
#include <simgear/misc/stdint.hxx> |
| 24 |
|
| 25 |
#define SWAP32(arg) sgIsLittleEndian() ? sg_bswap_32(arg) : arg |
| 26 |
#define SWAP64(arg) sgIsLittleEndian() ? sg_bswap_64(arg) : arg |
| 27 |
|
| 28 |
#define XDR_BYTES_PER_UNIT 4 |
| 29 |
|
| 30 |
typedef uint32_t xdr_data_t; /* 4 Bytes */ |
| 31 |
typedef uint64_t xdr_data2_t; /* 8 Bytes */ |
| 32 |
|
| 33 |
/* XDR 8bit integers */ |
| 34 |
xdr_data_t XDR_encode_int8 ( const int8_t & n_Val ); |
| 35 |
xdr_data_t XDR_encode_uint8 ( const uint8_t & n_Val ); |
| 36 |
int8_t XDR_decode_int8 ( const xdr_data_t & n_Val ); |
| 37 |
uint8_t XDR_decode_uint8 ( const xdr_data_t & n_Val ); |
| 38 |
|
| 39 |
/* XDR 16bit integers */ |
| 40 |
xdr_data_t XDR_encode_int16 ( const int16_t & n_Val ); |
| 41 |
xdr_data_t XDR_encode_uint16 ( const uint16_t & n_Val ); |
| 42 |
int16_t XDR_decode_int16 ( const xdr_data_t & n_Val ); |
| 43 |
uint16_t XDR_decode_uint16 ( const xdr_data_t & n_Val ); |
| 44 |
|
| 45 |
/* XDR 32bit integers */ |
| 46 |
xdr_data_t XDR_encode_int32 ( const int32_t & n_Val ); |
| 47 |
xdr_data_t XDR_encode_uint32 ( const uint32_t & n_Val ); |
| 48 |
int32_t XDR_decode_int32 ( const xdr_data_t & n_Val ); |
| 49 |
uint32_t XDR_decode_uint32 ( const xdr_data_t & n_Val ); |
| 50 |
|
| 51 |
/* XDR 64bit integers */ |
| 52 |
xdr_data2_t XDR_encode_int64 ( const int64_t & n_Val ); |
| 53 |
xdr_data2_t XDR_encode_uint64 ( const uint64_t & n_Val ); |
| 54 |
int64_t XDR_decode_int64 ( const xdr_data2_t & n_Val ); |
| 55 |
uint64_t XDR_decode_uint64 ( const xdr_data2_t & n_Val ); |
| 56 |
|
| 57 |
xdr_data_t XDR_encode_shortints32(const int v1, const int v2); |
| 58 |
void XDR_decode_shortints32(const xdr_data_t & n_Val, int &v1, int &v2); |
| 59 |
|
| 60 |
////////////////////////////////////////////////// |
| 61 |
// |
| 62 |
// FIXME: #1 these funtions must be fixed for |
| 63 |
// none IEEE-encoding architecturs |
| 64 |
// (eg. vax, big suns etc) |
| 65 |
// FIXME: #2 some compilers return 'double' |
| 66 |
// regardless of return-type 'float' |
| 67 |
// this must be fixed, too |
| 68 |
// FIXME: #3 some machines may need to use a |
| 69 |
// different endianess for floats! |
| 70 |
// |
| 71 |
////////////////////////////////////////////////// |
| 72 |
/* float */ |
| 73 |
xdr_data_t XDR_encode_float ( const float & f_Val ); |
| 74 |
float XDR_decode_float ( const xdr_data_t & f_Val ); |
| 75 |
|
| 76 |
/* double */ |
| 77 |
xdr_data2_t XDR_encode_double ( const double & d_Val ); |
| 78 |
double XDR_decode_double ( const xdr_data2_t & d_Val ); |
| 79 |
|
| 80 |
#endif |