Replaced usage of string with vector<unsigned char>
This commit is contained in:
		| @@ -3,11 +3,12 @@ | |||||||
| #include "demofilebitbuf.h" | #include "demofilebitbuf.h" | ||||||
| #include "netmessages.h" | #include "netmessages.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
| void ParsePacket(const char* packetBuf, const int numBytes) | void ParsePacket(const std::vector<unsigned char>& packet) | ||||||
| { | { | ||||||
|     assert(numBytes <= NET_MAX_PAYLOAD); |     assert(packet.size() <= NET_MAX_PAYLOAD); | ||||||
|     CBitRead bitBuf(packetBuf, numBytes); |     CBitRead bitBuf(packet.data(), packet.size()); | ||||||
|     while (bitBuf.GetNumBitsLeft() >= NETMSG_TYPE_BITS) |     while (bitBuf.GetNumBitsLeft() >= NETMSG_TYPE_BITS) | ||||||
|     { |     { | ||||||
|         uint32 typeId = bitBuf.ReadUBitLong(NETMSG_TYPE_BITS); |         uint32 typeId = bitBuf.ReadUBitLong(NETMSG_TYPE_BITS); | ||||||
| @@ -16,9 +17,9 @@ void ParsePacket(const char* packetBuf, const int numBytes) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void ParseSignonData(const std::string& signonData) | void ParseSignonData(const std::vector<unsigned char>& signonData) | ||||||
| { | { | ||||||
|     CBitRead bitbuf(signonData.data(), signonData.length()); |     CBitRead bitbuf(signonData.data(), signonData.size()); | ||||||
|     const char cmd = bitbuf.ReadChar(); |     const char cmd = bitbuf.ReadChar(); | ||||||
|     assert(cmd == dem_signon); |     assert(cmd == dem_signon); | ||||||
|     const int32 tick = bitbuf.ReadLong(); |     const int32 tick = bitbuf.ReadLong(); | ||||||
| @@ -28,10 +29,10 @@ void ParseSignonData(const std::string& signonData) | |||||||
|     assert(seq1 == seq2); |     assert(seq1 == seq2); | ||||||
|  |  | ||||||
|     const int32 numBytes = bitbuf.ReadLong(); |     const int32 numBytes = bitbuf.ReadLong(); | ||||||
|     std::string packet; |     std::vector<unsigned char> packet; | ||||||
|     packet.resize(numBytes); |     packet.resize(numBytes); | ||||||
|     bitbuf.ReadBytes(&packet[0], numBytes); |     bitbuf.ReadBytes(&packet[0], numBytes); | ||||||
|     ParsePacket(packet.data(), numBytes); |     ParsePacket(packet); | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(const int argc, const char* argv[]) | int main(const int argc, const char* argv[]) | ||||||
| @@ -56,7 +57,7 @@ int main(const int argc, const char* argv[]) | |||||||
|     int32 sequenceInfo1; |     int32 sequenceInfo1; | ||||||
|     int32 sequenceInfo2; |     int32 sequenceInfo2; | ||||||
|     democmdinfo_t cmdInfo; |     democmdinfo_t cmdInfo; | ||||||
|     char* packetBuf = (char*)malloc(NET_MAX_PAYLOAD); |     std::vector<unsigned char> packet; | ||||||
|     demoFile.ReadCmdHeader(cmd, tick); |     demoFile.ReadCmdHeader(cmd, tick); | ||||||
|  |  | ||||||
|     assert(cmd == dem_synctick && tick == 0); |     assert(cmd == dem_synctick && tick == 0); | ||||||
| @@ -70,13 +71,11 @@ int main(const int argc, const char* argv[]) | |||||||
|         switch (cmd) |         switch (cmd) | ||||||
|         { |         { | ||||||
|             case dem_packet: |             case dem_packet: | ||||||
|                 { |  | ||||||
|                 demoFile.ReadCmdInfo(cmdInfo); |                 demoFile.ReadCmdInfo(cmdInfo); | ||||||
|                 demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2); |                 demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2); | ||||||
|                 assert(sequenceInfo1 == sequenceInfo2); |                 assert(sequenceInfo1 == sequenceInfo2); | ||||||
|                     const int32 length = demoFile.ReadRawData(packetBuf, NET_MAX_PAYLOAD); |                 demoFile.ReadRawData(packet); | ||||||
|                     ParsePacket(packetBuf, length); |                 ParsePacket(packet); | ||||||
|                 } |  | ||||||
|                 break; |                 break; | ||||||
|             case dem_stop: |             case dem_stop: | ||||||
|                 assert(i == numFrames && tick == numTicks); |                 assert(i == numFrames && tick == numTicks); | ||||||
| @@ -91,7 +90,6 @@ int main(const int argc, const char* argv[]) | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     free(packetBuf); |  | ||||||
|     demoFile.Close(); |     demoFile.Close(); | ||||||
|  |  | ||||||
|     return 0; |     return 0; | ||||||
|   | |||||||
| @@ -124,7 +124,7 @@ int32 CDemoFile::ReadRawData( char *buffer, int32 length ) | |||||||
|     return size; |     return size; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool CDemoFile::ReadRawData(std::string& buf) | bool CDemoFile::ReadRawData(std::vector<unsigned char>& buf) | ||||||
| { | { | ||||||
|     if (!m_fileBuffer.size()) |     if (!m_fileBuffer.size()) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include <string> | #include <vector> | ||||||
|  |  | ||||||
| #define __STDC_FORMAT_MACROS | #define __STDC_FORMAT_MACROS | ||||||
| #include <inttypes.h> | #include <inttypes.h> | ||||||
| @@ -229,7 +229,7 @@ public: | |||||||
|  |  | ||||||
|     int32   ReadRawData( char *buffer, int32 length ); |     int32   ReadRawData( char *buffer, int32 length ); | ||||||
|  |  | ||||||
|     bool    ReadRawData(std::string& buf); |     bool    ReadRawData(std::vector<unsigned char>& buf); | ||||||
|  |  | ||||||
|     void    ReadSequenceInfo( int32 &nSeqNrIn, int32 &nSeqNrOutAck ); |     void    ReadSequenceInfo( int32 &nSeqNrIn, int32 &nSeqNrOutAck ); | ||||||
|  |  | ||||||
| @@ -241,13 +241,13 @@ public: | |||||||
|  |  | ||||||
|     const demoheader_t *GetDemoHeader() const; |     const demoheader_t *GetDemoHeader() const; | ||||||
|  |  | ||||||
|     const std::string& GetSignOnData() const; |     const std::vector<unsigned char>& GetSignOnData() const; | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     demoheader_t    m_DemoHeader;  //general demo info |     demoheader_t    m_DemoHeader;  //general demo info | ||||||
|  |  | ||||||
|     std::string m_signOnData; |     std::vector<unsigned char> m_signOnData; | ||||||
|     std::string m_fileBuffer; |     std::vector<unsigned char> m_fileBuffer; | ||||||
|  |  | ||||||
|     size_t m_fileBufferPos; |     size_t m_fileBufferPos; | ||||||
| }; | }; | ||||||
| @@ -257,7 +257,7 @@ inline const demoheader_t *CDemoFile::GetDemoHeader() const | |||||||
|     return &m_DemoHeader; |     return &m_DemoHeader; | ||||||
| } | } | ||||||
|  |  | ||||||
| inline const std::string& CDemoFile::GetSignOnData() const | inline const std::vector<unsigned char>& CDemoFile::GetSignOnData() const | ||||||
| { | { | ||||||
|     return m_signOnData; |     return m_signOnData; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user