From b7f58023d6596d96c36b904c02a81e0b52fc28f1 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 3 Nov 2010 23:15:47 +0100 Subject: Renamed write{Byte,Short,Long} to writeInt{8,16,32} Mainly for consistency with the client, and the general consensus was that these numbered versions were clearer. --- src/net/messagein.cpp | 12 ++++++------ src/net/messagein.hpp | 7 ++++--- src/net/messageout.cpp | 12 ++++++------ src/net/messageout.hpp | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src/net') diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 63fd8778..7d6de273 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -36,10 +36,10 @@ MessageIn::MessageIn(const char *data, int length): mPos(0) { // Read the message ID - mId = readShort(); + mId = readInt16(); } -int MessageIn::readByte() +int MessageIn::readInt8() { int value = -1; if (mPos < mLength) @@ -51,7 +51,7 @@ int MessageIn::readByte() return value; } -int MessageIn::readShort() +int MessageIn::readInt16() { int value = -1; if (mPos + 2 <= mLength) @@ -65,7 +65,7 @@ int MessageIn::readShort() return value; } -int MessageIn::readLong() +int MessageIn::readInt32() { int value = -1; if (mPos + 4 <= mLength) @@ -87,7 +87,7 @@ double MessageIn::readDouble() memcpy(&value, mData + mPos, sizeof(double)); mPos += sizeof(double); #else - int length = readByte(); + int length = readInt8(); std::istringstream i (readString(length)); i >> value; #endif @@ -99,7 +99,7 @@ std::string MessageIn::readString(int length) // Get string length if (length < 0) { - length = readShort(); + length = readInt16(); } // Make sure the string isn't erroneous diff --git a/src/net/messagein.hpp b/src/net/messagein.hpp index c6e49ab5..f01c1850 100644 --- a/src/net/messagein.hpp +++ b/src/net/messagein.hpp @@ -44,9 +44,10 @@ class MessageIn */ int getLength() const { return mLength; } - int readByte(); /**< Reads a byte. */ - int readShort(); /**< Reads a short. */ - int readLong(); /**< Reads a long. */ + int readInt8(); /**< Reads a byte. */ + int readInt16(); /**< Reads a short. */ + int readInt32(); /**< Reads a long. */ + /** * Reads a double. HACKY and should *not* be used for client * communication! diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 950da5f3..c8310c55 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -49,7 +49,7 @@ MessageOut::MessageOut(int id): mData = (char*) malloc(INITIAL_DATA_CAPACITY); mDataSize = INITIAL_DATA_CAPACITY; - writeShort(id); + writeInt16(id); } MessageOut::~MessageOut() @@ -79,14 +79,14 @@ MessageOut::expand(size_t bytes) } } -void MessageOut::writeByte(int value) +void MessageOut::writeInt8(int value) { expand(mPos + 1); mData[mPos] = value; mPos += 1; } -void MessageOut::writeShort(int value) +void MessageOut::writeInt16(int value) { expand(mPos + 2); uint16_t t = ENET_HOST_TO_NET_16(value); @@ -94,7 +94,7 @@ void MessageOut::writeShort(int value) mPos += 2; } -void MessageOut::writeLong(int value) +void MessageOut::writeInt32(int value) { expand(mPos + 4); uint32_t t = ENET_HOST_TO_NET_32(value); @@ -116,7 +116,7 @@ void MessageOut::writeDouble(double value) o.precision(std::numeric_limits< double >::digits10); o << value; std::string str = o.str(); - writeByte(str.size()); + writeInt8(str.size()); writeString(str, str.size()); #endif } @@ -138,7 +138,7 @@ MessageOut::writeString(const std::string &string, int length) if (length < 0) { // Write the length at the start if not fixed - writeShort(stringLength); + writeInt16(stringLength); length = stringLength; } else if (length < stringLength) diff --git a/src/net/messageout.hpp b/src/net/messageout.hpp index 270b7963..cf3e0c73 100644 --- a/src/net/messageout.hpp +++ b/src/net/messageout.hpp @@ -49,11 +49,11 @@ class MessageOut */ void clear(); - void writeByte(int value); /**< Writes an integer on one byte. */ + void writeInt8(int value); /**< Writes an integer on one byte. */ - void writeShort(int value); /**< Writes an integer on two bytes. */ + void writeInt16(int value); /**< Writes an integer on two bytes. */ - void writeLong(int value); /**< Writes an integer on four bytes. */ + void writeInt32(int value); /**< Writes an integer on four bytes. */ /** * Writes a double. HACKY and should *not* be used for client -- cgit v1.2.3-70-g09d2