Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
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
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
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
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
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}
@ LOG_LEVEL_TRACE
Definition Appender.h:18
std::uint32_t uint32
Definition Define.h:77
#define SF_LOG_TRACE(filterType__,...)
Definition Log.h:131
#define sLog
Definition Log.h:106
std::string & message()
Definition ByteBuffer.h:41
void hexlike() const
void print_storage() const
void textlike() const
size_t size() const
Definition ByteBuffer.h:609
ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize)
ByteBufferSourceException(size_t pos, size_t size, size_t valueSize)