Browse Source

Merge pull request #967 from EgzoT/EgzoT-OutputMessage_setBuffer_2

Add setBuffer() method to OutputMessage class
Konrad Kuśnierz 1 year ago
parent
commit
92532a958e
No account linked to committer's email address

+ 1
- 0
src/framework/luafunctions.cpp View File

@@ -814,6 +814,7 @@ void Application::registerLuaFunctions()
814 814
     // OutputMessage
815 815
     g_lua.registerClass<OutputMessage>();
816 816
     g_lua.bindClassStaticFunction<OutputMessage>("create", []{ return OutputMessagePtr(new OutputMessage); });
817
+    g_lua.bindClassMemberFunction<OutputMessage>("setBuffer", &OutputMessage::setBuffer);
817 818
     g_lua.bindClassMemberFunction<OutputMessage>("getBuffer", &OutputMessage::getBuffer);
818 819
     g_lua.bindClassMemberFunction<OutputMessage>("reset", &OutputMessage::reset);
819 820
     g_lua.bindClassMemberFunction<OutputMessage>("addU8", &OutputMessage::addU8);

+ 10
- 0
src/framework/net/outputmessage.cpp View File

@@ -35,6 +35,16 @@ void OutputMessage::reset()
35 35
     m_messageSize = 0;
36 36
 }
37 37
 
38
+void OutputMessage::setBuffer(const std::string& buffer)
39
+{
40
+    int len = buffer.size();
41
+    checkWrite(MAX_HEADER_SIZE + len);
42
+    memcpy(m_buffer + MAX_HEADER_SIZE, buffer.c_str(), len);
43
+    m_writePos = MAX_HEADER_SIZE;
44
+    m_headerPos = MAX_HEADER_SIZE;
45
+    m_messageSize = len;
46
+}
47
+
38 48
 void OutputMessage::addU8(uint8 value)
39 49
 {
40 50
     checkWrite(1);

+ 1
- 0
src/framework/net/outputmessage.h View File

@@ -40,6 +40,7 @@ public:
40 40
 
41 41
     void reset();
42 42
 
43
+    void setBuffer(const std::string& buffer);
43 44
     std::string getBuffer() { return std::string((char*)m_buffer + m_headerPos, m_messageSize); }
44 45
 
45 46
     void addU8(uint8 value);

Loading…
Cancel
Save