/
ByteBuffer.cpp
113 lines (95 loc) · 3.18 KB
/
ByteBuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ByteBuffer.h"
#include "Log.h"
#include <ace/Stack_Trace.h>
#include <sstream>
ByteBufferPositionException::ByteBufferPositionException(bool add, size_t pos,
size_t size, size_t valueSize)
{
std::ostringstream ss;
ACE_Stack_Trace trace;
ss << "Attempted to " << (add ? "put" : "get") << " value with size: "
<< valueSize << " in ByteBuffer (pos: " << pos << " size: " << size
<< ")\n\n" << trace.c_str();
message().assign(ss.str());
}
ByteBufferSourceException::ByteBufferSourceException(size_t pos, size_t size,
size_t valueSize)
{
std::ostringstream ss;
ACE_Stack_Trace trace;
ss << "Attempted to put a "
<< (valueSize > 0 ? "NULL-pointer" : "zero-sized value")
<< " in ByteBuffer (pos: " << pos << " size: " << size << ")\n\n"
<< trace.c_str();
message().assign(ss.str());
}
void ByteBuffer::print_storage() const
{
if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output
return;
std::ostringstream o;
o << "STORAGE_SIZE: " << size();
for (uint32 i = 0; i < size(); ++i)
o << read<uint8>(i) << " - ";
o << " ";
sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str());
}
void ByteBuffer::textlike() const
{
if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output
return;
std::ostringstream o;
o << "STORAGE_SIZE: " << size();
for (uint32 i = 0; i < size(); ++i)
{
char buf[1];
snprintf(buf, 1, "%c", read<uint8>(i));
o << buf;
}
o << " ";
sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str());
}
void ByteBuffer::hexlike() const
{
if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output
return;
uint32 j = 1, k = 1;
std::ostringstream o;
o << "STORAGE_SIZE: " << size();
for (uint32 i = 0; i < size(); ++i)
{
char buf[3];
snprintf(buf, 1, "%2X ", read<uint8>(i));
if ((i == (j * 8)) && ((i != (k * 16))))
{
o << "| ";
++j;
}
else if (i == (k * 16))
{
o << "\n";
++k;
++j;
}
o << buf;
}
o << " ";
sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str());
}