Merge pull request #967 from EgzoT/EgzoT-OutputMessage_setBuffer_2

Add setBuffer() method to OutputMessage class
This commit is contained in:
Konrad Kuśnierz 2019-03-06 14:46:24 +01:00 committed by GitHub
commit 92532a958e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

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

View File

@ -35,6 +35,16 @@ void OutputMessage::reset()
m_messageSize = 0; m_messageSize = 0;
} }
void OutputMessage::setBuffer(const std::string& buffer)
{
int len = buffer.size();
checkWrite(MAX_HEADER_SIZE + len);
memcpy(m_buffer + MAX_HEADER_SIZE, buffer.c_str(), len);
m_writePos = MAX_HEADER_SIZE;
m_headerPos = MAX_HEADER_SIZE;
m_messageSize = len;
}
void OutputMessage::addU8(uint8 value) void OutputMessage::addU8(uint8 value)
{ {
checkWrite(1); checkWrite(1);

View File

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