- more updates to support big endian

This commit is contained in:
Mark Vejvoda 2012-11-01 16:25:15 +00:00
parent c1ec7a395c
commit 56bcd62d88
2 changed files with 13 additions and 8 deletions

View File

@ -109,10 +109,11 @@ NetworkMessageIntro::NetworkMessageIntro(int32 sessionId,const string &versionSt
bool NetworkMessageIntro::receive(Socket* socket) {
bool result = NetworkMessage::receive(socket, &data, sizeof(data), true);
fromEndian();
data.name.nullTerminate();
data.versionString.nullTerminate();
data.language.nullTerminate();
fromEndian();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] get nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",__FILE__,__FUNCTION__,__LINE__,data.playerIndex,data.sessionId);
return result;
}

View File

@ -17,14 +17,18 @@
namespace Shared{ namespace PlatformByteOrder {
template<class T> T EndianReverse(T t) {
unsigned char uc[sizeof t];
memcpy(uc, &t, sizeof t);
// unsigned char uc[sizeof t];
// memcpy(uc, &t, sizeof t);
//
// for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
// std::swap(*b, *e);
// }
// memcpy(&t, uc, sizeof t);
// return t;
for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
std::swap(*b, *e);
}
memcpy(&t, uc, sizeof t);
return t;
char& raw = reinterpret_cast<char&>(t);
std::reverse(&raw, &raw + sizeof(T));
return t;
}
static bool isBigEndian() {