Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
WorldPacket.cpp
Go to the documentation of this file.
3
4#include <iterator>
5
6namespace Divide
7{
9 : WorldPacket( OPCodes::MSG_NOP )
10 {
11 }
12
13 WorldPacket::WorldPacket( const OPCodes::ValueType code, const size_t res )
14 : ByteBuffer()
15 , _opcode( code )
16 {
17 _storage.reserve( res );
18 }
19
20 void WorldPacket::Initialize( const U16 opcode, const size_t newres )
21 {
22 clear();
23 _storage.reserve( newres );
24 _opcode = opcode;
25 }
26
27 bool WorldPacket::loadFromBuffer( boost::asio::streambuf& buf )
28 {
29 size_t storageSize = 0u;
30
31 std::istream is( &buf );
32 is.read(reinterpret_cast<char*>(&_opcode), sizeof(_opcode));
33 is.read(reinterpret_cast<char*>(&_wpos), sizeof( _wpos ));
34 is.read(reinterpret_cast<char*>(&_rpos), sizeof( _rpos ));
35 is.read(reinterpret_cast<char*>(&storageSize), sizeof( storageSize ));
36
37 if (storageSize > 0u)
38 {
39 _storage.resize(storageSize);
40 is.read( reinterpret_cast<char*>(_storage.data()), storageSize * sizeof ( _storage[0] ) );
41 }
42 else
43 {
45 }
46
47 return true;
48 }
49
50 bool WorldPacket::saveToBuffer( boost::asio::streambuf& buf ) const
51 {
52 const size_t storageSize = _storage.size();
53
54 std::ostream os( &buf );
55 os.write((const char*)&_opcode, sizeof( _opcode ));
56 os.write((const char*)&_wpos, sizeof( _wpos ));
57 os.write((const char*)&_rpos, sizeof( _rpos ));
58 os.write((const char*)&storageSize, sizeof (storageSize));
59 if (storageSize > 0u)
60 {
61 os.write( (const char*)_storage.data(), storageSize * sizeof( _storage[0] ) );
62 }
63 return !os.bad();
64 }
65} // namespace Divide
size_t storageSize() const noexcept
Returns the total size (in bytes) of the underlying storage, regardles of wpos and rpos.
Definition: ByteBuffer.inl:357
void clear() noexcept
Resets the entire storage and the read and write positions.
Definition: ByteBuffer.cpp:28
vector< Byte > _storage
Definition: ByteBuffer.h:193
int32_t ValueType
Definition: OPCodesTpl.h:15
WorldPacket() noexcept
Definition: WorldPacket.cpp:8
void Initialize(const U16 opCode, const size_t newres=200)
Definition: WorldPacket.cpp:20
bool saveToBuffer(boost::asio::streambuf &buf) const
Definition: WorldPacket.cpp:50
bool loadFromBuffer(boost::asio::streambuf &buf)
Definition: WorldPacket.cpp:27
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint16_t U16
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
Definition: Vector.h:52