2005-09-18 12:37:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Tiny XDR implementation for flightgear
|
|
|
|
// written by Oliver Schroeder
|
2005-10-30 18:01:51 +00:00
|
|
|
// released to the public domain
|
2005-09-18 12:37:18 +00:00
|
|
|
//
|
|
|
|
// This implementation is not complete, but implements
|
|
|
|
// everything we need.
|
|
|
|
//
|
|
|
|
// For further reading on XDR read RFC 1832.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-02-17 09:43:33 +00:00
|
|
|
#include <string>
|
|
|
|
|
2005-11-01 13:41:49 +00:00
|
|
|
#include "tiny_xdr.hxx"
|
2005-09-18 12:37:18 +00:00
|
|
|
|
|
|
|
/* XDR 8bit integers */
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_int8 ( const int8_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_uint8 ( const uint8_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_int8 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<int8_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_uint8 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<uint8_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XDR 16bit integers */
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_int16 ( const int16_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_uint16 ( const uint16_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_int16 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<int16_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_uint16 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<uint16_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XDR 32bit integers */
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_int32 ( const int32_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_uint32 ( const uint32_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_int32 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<int32_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_uint32 ( const xdr_data_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<uint32_t> (SWAP32(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XDR 64bit integers */
|
|
|
|
xdr_data2_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_int64 ( const int64_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
xdr_data2_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_uint64 ( const uint64_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (SWAP64(static_cast<xdr_data2_t> (n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_int64 ( const xdr_data2_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<int64_t> (SWAP64(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_uint64 ( const xdr_data2_t & n_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
|
|
|
return (static_cast<uint64_t> (SWAP64(n_Val)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* float */
|
|
|
|
xdr_data_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_float ( const float & f_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
2005-12-02 16:43:50 +00:00
|
|
|
union {
|
|
|
|
xdr_data_t x;
|
|
|
|
float f;
|
|
|
|
} tmp;
|
2005-09-18 12:37:18 +00:00
|
|
|
|
2005-12-02 16:43:50 +00:00
|
|
|
tmp.f = f_Val;
|
|
|
|
return (XDR_encode_int32 (tmp.x));
|
2005-09-18 12:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_float ( const xdr_data_t & f_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
2005-12-02 16:43:50 +00:00
|
|
|
union {
|
|
|
|
xdr_data_t x;
|
|
|
|
float f;
|
|
|
|
} tmp;
|
2005-09-18 12:37:18 +00:00
|
|
|
|
2005-12-02 16:43:50 +00:00
|
|
|
tmp.x = XDR_decode_int32 (f_Val);
|
|
|
|
return tmp.f;
|
2005-09-18 12:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* double */
|
|
|
|
xdr_data2_t
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_encode_double ( const double & d_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
2005-12-02 16:43:50 +00:00
|
|
|
union {
|
|
|
|
xdr_data2_t x;
|
|
|
|
double d;
|
|
|
|
} tmp;
|
2005-09-18 12:37:18 +00:00
|
|
|
|
2005-12-02 16:43:50 +00:00
|
|
|
tmp.d = d_Val;
|
|
|
|
return (XDR_encode_int64 (tmp.x));
|
2005-09-18 12:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2005-09-22 11:47:58 +00:00
|
|
|
XDR_decode_double ( const xdr_data2_t & d_Val )
|
2005-09-18 12:37:18 +00:00
|
|
|
{
|
2005-12-02 16:43:50 +00:00
|
|
|
union {
|
|
|
|
xdr_data2_t x;
|
|
|
|
double d;
|
|
|
|
} tmp;
|
2005-09-18 12:37:18 +00:00
|
|
|
|
2005-12-02 16:43:50 +00:00
|
|
|
tmp.x = XDR_decode_int64 (d_Val);
|
|
|
|
return tmp.d;
|
2005-09-18 12:37:18 +00:00
|
|
|
}
|
|
|
|
|