1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2009 Kevin Rosenberg
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License (version 2) as
7 ** published by the Free Software Foundation.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ******************************************************************************/
27 #include "ctsupport.h"
28 #include "fnetorderstream.h"
32 ConvertNetworkOrder (void* buffer, size_t bytes)
34 #ifndef WORDS_BIGENDIAN
38 char* start = static_cast<char*>(buffer);
39 char* end = start + bytes - 1; // last byte
40 size_t nSwap = bytes / 2;
43 unsigned char c = *start;
51 ConvertReverseNetworkOrder (void* buffer, size_t bytes)
53 #ifdef WORDS_BIGENDIAN
57 char* start = static_cast<char*>(buffer);
58 char* end = start + bytes - 1; // last byte
59 size_t nSwap = bytes / 2;
62 unsigned char c = *start;
70 fnetorderstream::writeInt16 (kuint16 n) {
71 #ifndef WORDS_BIGENDIAN
74 write (reinterpret_cast<const char*>(&n), 2);
78 fnetorderstream::writeInt32 (kuint32 n) {
79 #ifndef WORDS_BIGENDIAN
82 write (reinterpret_cast<const char*>(&n), 4);
86 fnetorderstream::writeFloat32 (kfloat32 n) {
87 #ifndef WORDS_BIGENDIAN
90 write (reinterpret_cast<const char*>(&n), 4);
94 fnetorderstream::writeFloat64 (kfloat64 n) {
95 #ifndef WORDS_BIGENDIAN
98 write (reinterpret_cast<const char*>(&n), 8);
102 fnetorderstream::readInt16 (kuint16& n) {
103 read (reinterpret_cast<char*>(&n), 2);
104 #ifndef WORDS_BIGENDIAN
110 fnetorderstream::readInt32 (kuint32& n) {
111 read (reinterpret_cast<char*>(&n), 4);
112 #ifndef WORDS_BIGENDIAN
118 fnetorderstream::readFloat32 (kfloat32& n) {
119 read (reinterpret_cast<char*>(&n), 4);
120 #ifndef WORDS_BIGENDIAN
126 fnetorderstream::readFloat64 (kfloat64& n) {
127 read (reinterpret_cast<char*>(&n), 8);
128 #ifndef WORDS_BIGENDIAN
136 frnetorderstream::writeInt16 (kuint16 n) {
137 #ifdef WORDS_BIGENDIAN
140 write (reinterpret_cast<char*>(&n), 2);
144 frnetorderstream::writeInt32 (kuint32 n) {
145 #ifdef WORDS_BIGENDIAN
148 write (reinterpret_cast<char*>(&n), 4);
152 frnetorderstream::writeFloat32 (kfloat32 n) {
153 #ifdef WORDS_BIGENDIAN
156 write (reinterpret_cast<char*>(&n), 4);
160 frnetorderstream::writeFloat64 (kfloat64 n) {
161 #ifdef WORDS_BIGENDIAN
164 write (reinterpret_cast<char*>(&n), 8);
168 frnetorderstream::readInt16 (kuint16& n) {
169 read (reinterpret_cast<char*>(&n), 2);
170 #ifdef WORDS_BIGENDIAN
176 frnetorderstream::readInt32 (kuint32& n) {
177 read (reinterpret_cast<char*>(&n), 4);
178 #ifdef WORDS_BIGENDIAN
184 frnetorderstream::readFloat32 (kfloat32& n) {
185 read (reinterpret_cast<char*>(&n), 4);
186 #ifdef WORDS_BIGENDIAN
192 frnetorderstream::readFloat64 (kfloat64& n) {
193 read (reinterpret_cast<char*>(&n), 8);
194 #ifdef WORDS_BIGENDIAN