1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2001 Kevin Rosenberg
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
29 #include "ctsupport.h"
30 #include "fnetorderstream.h"
34 ConvertNetworkOrder (void* buffer, size_t bytes)
36 #ifndef WORDS_BIGENDIAN
40 char* start = static_cast<char*>(buffer);
41 char* end = start + bytes - 1; // last byte
42 size_t nSwap = bytes / 2;
45 unsigned char c = *start;
53 ConvertReverseNetworkOrder (void* buffer, size_t bytes)
55 #ifdef WORDS_BIGENDIAN
59 char* start = static_cast<char*>(buffer);
60 char* end = start + bytes - 1; // last byte
61 size_t nSwap = bytes / 2;
64 unsigned char c = *start;
72 fnetorderstream::writeInt16 (kuint16 n) {
73 #ifndef WORDS_BIGENDIAN
76 write (reinterpret_cast<const char*>(&n), 2);
80 fnetorderstream::writeInt32 (kuint32 n) {
81 #ifndef WORDS_BIGENDIAN
84 write (reinterpret_cast<const char*>(&n), 4);
88 fnetorderstream::writeFloat32 (kfloat32 n) {
89 #ifndef WORDS_BIGENDIAN
92 write (reinterpret_cast<const char*>(&n), 4);
96 fnetorderstream::writeFloat64 (kfloat64 n) {
97 #ifndef WORDS_BIGENDIAN
100 write (reinterpret_cast<const char*>(&n), 8);
104 fnetorderstream::readInt16 (kuint16& n) {
105 read (reinterpret_cast<char*>(&n), 2);
106 #ifndef WORDS_BIGENDIAN
112 fnetorderstream::readInt32 (kuint32& n) {
113 read (reinterpret_cast<char*>(&n), 4);
114 #ifndef WORDS_BIGENDIAN
120 fnetorderstream::readFloat32 (kfloat32& n) {
121 read (reinterpret_cast<char*>(&n), 4);
122 #ifndef WORDS_BIGENDIAN
128 fnetorderstream::readFloat64 (kfloat64& n) {
129 read (reinterpret_cast<char*>(&n), 8);
130 #ifndef WORDS_BIGENDIAN
138 frnetorderstream::writeInt16 (kuint16 n) {
139 #ifdef WORDS_BIGENDIAN
142 write (reinterpret_cast<char*>(&n), 2);
146 frnetorderstream::writeInt32 (kuint32 n) {
147 #ifdef WORDS_BIGENDIAN
150 write (reinterpret_cast<char*>(&n), 4);
154 frnetorderstream::writeFloat32 (kfloat32 n) {
155 #ifdef WORDS_BIGENDIAN
158 write (reinterpret_cast<char*>(&n), 4);
162 frnetorderstream::writeFloat64 (kfloat64 n) {
163 #ifdef WORDS_BIGENDIAN
166 write (reinterpret_cast<char*>(&n), 8);
170 frnetorderstream::readInt16 (kuint16& n) {
171 read (reinterpret_cast<char*>(&n), 2);
172 #ifdef WORDS_BIGENDIAN
178 frnetorderstream::readInt32 (kuint32& n) {
179 read (reinterpret_cast<char*>(&n), 4);
180 #ifdef WORDS_BIGENDIAN
186 frnetorderstream::readFloat32 (kfloat32& n) {
187 read (reinterpret_cast<char*>(&n), 4);
188 #ifdef WORDS_BIGENDIAN
194 frnetorderstream::readFloat64 (kfloat64& n) {
195 read (reinterpret_cast<char*>(&n), 8);
196 #ifdef WORDS_BIGENDIAN