]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/tiny_xdr.hpp
Use our own stdint.hxx implementation.
[flightgear.git] / src / MultiPlayer / tiny_xdr.hpp
1 //////////////////////////////////////////////////////////////////////
2 //
3 //      Tiny XDR implementation for flightgear
4 //      written by Oliver Schroeder
5 //      released to the puiblic 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
26 #if BYTE_ORDER == BIG_ENDIAN
27 #   define SWAP32(arg) arg
28 #   define SWAP64(arg) arg
29 #   define LOW  0
30 #   define HIGH 1
31 #else
32 #   define SWAP32(arg) sg_bswap_32(arg)
33 #   define SWAP64(arg) sg_bswap_64(arg)
34 #   define LOW  1
35 #   define HIGH 0
36 #endif
37
38 #define XDR_BYTES_PER_UNIT  4
39
40 typedef uint32_t    xdr_data_t;      /* 4 Bytes */
41 typedef uint64_t    xdr_data2_t;     /* 8 Bytes */
42
43 /* XDR 8bit integers */
44 xdr_data_t      XDR_encode_int8     ( const int8_t &  n_Val );
45 xdr_data_t      XDR_encode_uint8    ( const uint8_t & n_Val );
46 int8_t          XDR_decode_int8     ( const xdr_data_t & n_Val );
47 uint8_t         XDR_decode_uint8    ( const xdr_data_t & n_Val );
48
49 /* XDR 16bit integers */
50 xdr_data_t      XDR_encode_int16    ( const int16_t & n_Val );
51 xdr_data_t      XDR_encode_uint16   ( const uint16_t & n_Val );
52 int16_t         XDR_decode_int16    ( const xdr_data_t & n_Val );
53 uint16_t        XDR_decode_uint16   ( const xdr_data_t & n_Val );
54
55 /* XDR 32bit integers */
56 xdr_data_t      XDR_encode_int32    ( const int32_t & n_Val );
57 xdr_data_t      XDR_encode_uint32   ( const uint32_t & n_Val );
58 int32_t         XDR_decode_int32    ( const xdr_data_t & n_Val );
59 uint32_t        XDR_decode_uint32   ( const xdr_data_t & n_Val );
60
61 /* XDR 64bit integers */
62 xdr_data2_t     XDR_encode_int64    ( const int64_t & n_Val );
63 xdr_data2_t     XDR_encode_uint64   ( const uint64_t & n_Val );
64 int64_t         XDR_decode_int64    ( const xdr_data2_t & n_Val );
65 uint64_t        XDR_decode_uint64   ( const xdr_data2_t & n_Val );
66
67 //////////////////////////////////////////////////
68 //
69 //  FIXME: #1 these funtions must be fixed for
70 //         none IEEE-encoding architecturs
71 //         (eg. vax, big suns etc)
72 //  FIXME: #2 some compilers return 'double'
73 //         regardless of return-type 'float'
74 //         this must be fixed, too
75 //  FIXME: #3 some machines may need to use a
76 //         different endianess for floats!
77 //
78 //////////////////////////////////////////////////
79 /* float */
80 xdr_data_t      XDR_encode_float    ( const float & f_Val );
81 float           XDR_decode_float    ( const xdr_data_t & f_Val );
82
83 /* double */
84 xdr_data2_t     XDR_encode_double   ( const double & d_Val );
85 double          XDR_decode_double   ( const xdr_data2_t & d_Val );
86
87 #endif