Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
ByteBuffer.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
ByteBuffer.h
"
7
#include "
Common.h
"
8
#include "
Log.h
"
9
10
#include <sstream>
11
12
ByteBufferPositionException::ByteBufferPositionException
(
bool
add,
size_t
pos,
13
size_t
size,
size_t
valueSize)
14
{
15
std::ostringstream ss;
16
17
ss <<
"Attempted to "
<< (add ?
"put"
:
"get"
) <<
" value with size: "
18
<< valueSize <<
" in ByteBuffer (pos: "
<< pos <<
" size: "
<< size
19
<<
")"
;
20
21
message
().assign(ss.str());
22
printf(
"\nError Message => [%s]\n\n"
,
message
().c_str());
23
}
24
25
ByteBufferSourceException::ByteBufferSourceException
(
size_t
pos,
size_t
size,
26
size_t
valueSize)
27
{
28
std::ostringstream ss;
29
30
ss <<
"Attempted to put a "
31
<< (valueSize > 0 ?
"NULL-pointer"
:
"zero-sized value"
)
32
<<
" in ByteBuffer (pos: "
<< pos <<
" size: "
<< size <<
")"
;
33
34
message
().assign(ss.str());
35
}
36
37
void
ByteBuffer::print_storage
()
const
38
{
39
if
(!
sLog
->ShouldLog(
"network"
,
LogLevel::LOG_LEVEL_TRACE
))
// optimize disabled trace output
40
return
;
41
42
std::ostringstream o;
43
o <<
"STORAGE_SIZE: "
<<
size
();
44
for
(
uint32
i = 0; i <
size
(); ++i)
45
o <<
read<uint8>
(i) <<
" - "
;
46
o <<
" "
;
47
48
SF_LOG_TRACE
(
"network"
,
"%s"
, o.str().c_str());
49
}
50
51
void
ByteBuffer::textlike
()
const
52
{
53
if
(!
sLog
->ShouldLog(
"network"
,
LogLevel::LOG_LEVEL_TRACE
))
// optimize disabled trace output
54
return
;
55
56
std::ostringstream o;
57
o <<
"STORAGE_SIZE: "
<<
size
();
58
for
(
uint32
i = 0; i <
size
(); ++i)
59
{
60
char
buf[2];
61
snprintf(buf,
sizeof
(buf),
"%c"
,
read<uint8>
(i));
62
o << buf;
63
}
64
o <<
" "
;
65
SF_LOG_TRACE
(
"network"
,
"%s"
, o.str().c_str());
66
}
67
68
void
ByteBuffer::hexlike
()
const
69
{
70
if
(!
sLog
->ShouldLog(
"network"
,
LogLevel::LOG_LEVEL_TRACE
))
// optimize disabled trace output
71
return
;
72
73
uint32
j = 1, k = 1;
74
75
std::ostringstream o;
76
o <<
"STORAGE_SIZE: "
<<
size
();
77
78
for
(
uint32
i = 0; i <
size
(); ++i)
79
{
80
char
buf[4];
81
snprintf(buf,
sizeof
(buf),
"%2X "
,
read<uint8>
(i));
82
if
((i == (j * 8)) && ((i != (k * 16))))
83
{
84
o <<
"| "
;
85
++j;
86
}
87
else
if
(i == (k * 16))
88
{
89
o <<
"\n"
;
90
++k;
91
++j;
92
}
93
94
o << buf;
95
}
96
o <<
" "
;
97
SF_LOG_TRACE
(
"network"
,
"%s"
, o.str().c_str());
98
}
LogLevel::LOG_LEVEL_TRACE
@ LOG_LEVEL_TRACE
Definition
Appender.h:18
ByteBuffer.h
Common.h
uint32
std::uint32_t uint32
Definition
Define.h:77
Log.h
SF_LOG_TRACE
#define SF_LOG_TRACE(filterType__,...)
Definition
Log.h:131
sLog
#define sLog
Definition
Log.h:106
ByteBufferException::message
std::string & message()
Definition
ByteBuffer.h:41
ByteBuffer::hexlike
void hexlike() const
Definition
ByteBuffer.cpp:68
ByteBuffer::print_storage
void print_storage() const
Definition
ByteBuffer.cpp:37
ByteBuffer::textlike
void textlike() const
Definition
ByteBuffer.cpp:51
ByteBuffer::size
size_t size() const
Definition
ByteBuffer.h:609
ByteBuffer::read
T read()
Definition
ByteBuffer.h:511
ByteBufferPositionException::ByteBufferPositionException
ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize)
Definition
ByteBuffer.cpp:12
ByteBufferSourceException::ByteBufferSourceException
ByteBufferSourceException(size_t pos, size_t size, size_t valueSize)
Definition
ByteBuffer.cpp:25
src
server
shared
Packets
ByteBuffer.cpp
Generated on
for Project SkyFire Core by
1.17.0