--- a/sources/network/bytestream.cpp Sun Dec 14 19:38:47 2014 +0200 +++ b/sources/network/bytestream.cpp Sun Dec 14 19:42:43 2014 +0200 @@ -65,7 +65,15 @@ } // ------------------------------------------------------------------------------------------------- -METHOD Bytestream::operator= (const Bytestream& other) -> Bytestream& +// +Bytestream::~Bytestream() +{ + delete m_data; +} + +// ------------------------------------------------------------------------------------------------- +METHOD +Bytestream::operator= (const Bytestream& other) -> Bytestream& { init (other.data(), other.written_length()); return *this; @@ -73,14 +81,8 @@ // ------------------------------------------------------------------------------------------------- // -Bytestream::~Bytestream() -{ - delete m_data; -} - -// ------------------------------------------------------------------------------------------------- -// -void Bytestream::resize (unsigned long newsize) +METHOD +Bytestream::resize (unsigned long newsize) -> void { Vector<unsigned char> olddata; unsigned long oldsize = 0L; @@ -102,7 +104,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::init (const unsigned char* data, unsigned long length) +METHOD +Bytestream::init (const unsigned char* data, unsigned long length) -> void { resize (length); memcpy (m_data, data, length); @@ -112,7 +115,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::clear() +METHOD +Bytestream::clear() -> void { m_cursor = &m_data[0]; m_writtenLength = 0; @@ -132,7 +136,8 @@ // ------------------------------------------------------------------------------------------------- // -char Bytestream::read_byte() +METHOD +Bytestream::read_byte() -> char { ensure_read_space (1); return *m_cursor++; @@ -140,7 +145,8 @@ // ------------------------------------------------------------------------------------------------- // -short int Bytestream::read_short() +METHOD +Bytestream::read_short() -> short int { ensure_read_space (2); short int result = 0; @@ -154,7 +160,8 @@ // ------------------------------------------------------------------------------------------------- // -long int Bytestream::read_long() +METHOD +Bytestream::read_long() -> long int { ensure_read_space (4); long int result = 0; @@ -168,7 +175,8 @@ // ------------------------------------------------------------------------------------------------- // -float Bytestream::read_float() +METHOD +Bytestream::read_float() -> float { int value = read_long(); return reinterpret_cast<float&> (value); @@ -176,7 +184,8 @@ // ------------------------------------------------------------------------------------------------- // -String Bytestream::read_string() +METHOD +Bytestream::read_string() -> String { // Zandronum sends strings of maximum 2048 characters, though it only // reads 2047-character long ones so I guess we can follow up and do @@ -219,7 +228,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write (unsigned char val) +METHOD +Bytestream::write (unsigned char val) -> void { *m_cursor++ = val; m_writtenLength++; @@ -227,7 +237,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write (const unsigned char* val, unsigned int length) +METHOD +Bytestream::write (const unsigned char* val, unsigned int length) -> void { grow_to_fit (length); memcpy (m_cursor, val, length); @@ -237,7 +248,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::grow_to_fit (unsigned long bytes) +METHOD +Bytestream::grow_to_fit (unsigned long bytes) -> void { if (space_left() < bytes) resize (allocated_size() + bytes + 128); @@ -245,7 +257,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_byte (char val) +METHOD +Bytestream::write_byte (char val) -> void { grow_to_fit (1); write (val); @@ -253,7 +266,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_short (short int val) +METHOD +Bytestream::write_short (short int val) -> void { grow_to_fit (2); @@ -263,7 +277,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_long (long int val) +METHOD +Bytestream::write_long (long int val) -> void { grow_to_fit (4); @@ -273,7 +288,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_float (float val) +METHOD +Bytestream::write_float (float val) -> void { // I know this is probably dangerous but this is what Zandronum does so yeah write_long (reinterpret_cast<int&> (val)); @@ -281,7 +297,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_string (const String& val) +METHOD +Bytestream::write_string (const String& val) -> void { grow_to_fit (val.length() + 1); write (reinterpret_cast<const unsigned char*> (val.chars()), val.length()); @@ -290,7 +307,8 @@ // ------------------------------------------------------------------------------------------------- // -void Bytestream::write_buffer (const Bytestream& other) +METHOD +Bytestream::write_buffer (const Bytestream& other) -> void { write (other.data(), other.written_length()); }