IRC_SERVER
By @hyunjunk (hyunjun2372@gmail.com)
Loading...
Searching...
No Matches
MsgBlock.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstring>
4
5#include "Core/Core.hpp"
6using namespace IRCCore;
7
9
10namespace IRC
11{
12struct MsgBlock;
13
14/** Message block for managing the fixed Constants::MESSAGE_LEN_MAX size message data.
15 *
16 * @details new/delete overrided with memory pool.
17 */
18struct MsgBlock : public FlexibleMemoryPoolingBase<MsgBlock>
19{
20public:
22 size_t MsgLen;
23
25 : Msg()
26 , MsgLen(0)
27 {
28 Msg[0] = '\0'; //< Not necessary. Just for debug.
29 }
30
31 FORCEINLINE MsgBlock(const char* str, size_t msgLen)
32 : Msg()
33 , MsgLen(msgLen)
34 {
35 // If the string is too long, truncate it.
36 if (msgLen >= MESSAGE_LEN_MAX)
37 {
39 }
40 std::memcpy(Msg, str, MsgLen);
41 }
42
43 FORCEINLINE MsgBlock(const std::string& str)
44 : Msg()
45 , MsgLen(str.size())
46 {
47 // If the string is too long, truncate it.
48 if (str.size() >= MESSAGE_LEN_MAX)
49 {
50 MsgLen = MESSAGE_LEN_MAX - CRLF_LEN_2;
51 }
52 std::memcpy(Msg, str.c_str(), MsgLen);
53 }
54};
55
56} // namespace IRC
#define FORCEINLINE
Definition AttributeDefines.hpp:55
Base class for memory pooling with new/delete operator overloading.
Definition FlexibleMemoryPoolingBase.hpp:39
Definition ControlBlock.hpp:7
Definition ChannelControlBlock.hpp:12
@ CRLF_LEN_2
Definition IrcConstants.hpp:21
@ MESSAGE_LEN_MAX
Definition IrcConstants.hpp:18
Message block for managing the fixed Constants::MESSAGE_LEN_MAX size message data.
Definition MsgBlock.hpp:19
char Msg[MESSAGE_LEN_MAX]
Definition MsgBlock.hpp:21
MsgBlock(const char *str, size_t msgLen)
Definition MsgBlock.hpp:31
size_t MsgLen
Definition MsgBlock.hpp:22
MsgBlock()
Definition MsgBlock.hpp:24
MsgBlock(const std::string &str)
Definition MsgBlock.hpp:43