allow usage of network messages in extended opcode

This commit is contained in:
Eduardo Bart
2012-05-14 20:13:48 -03:00
parent 2478809945
commit 7bca3de8eb
6 changed files with 42 additions and 26 deletions

View File

@@ -30,28 +30,16 @@ InputMessage::InputMessage()
void InputMessage::reset()
{
m_messageSize = 0;
m_readPos = MAX_HEADER_SIZE;
m_headerPos = MAX_HEADER_SIZE;
}
void InputMessage::setHeaderSize(uint16 size)
void InputMessage::setBuffer(const std::string& buffer)
{
m_headerPos = MAX_HEADER_SIZE - size;
m_readPos = m_headerPos;
}
void InputMessage::fillBuffer(uint8 *buffer, uint16 size)
{
memcpy(m_buffer + m_readPos, buffer, size);
m_messageSize += size;
}
bool InputMessage::readChecksum()
{
uint32_t receivedCheck = getU32();
uint32 checksum = Fw::getAdlerChecksum(m_buffer + m_readPos, getUnreadSize());
return receivedCheck == checksum;
memcpy(m_buffer + MAX_HEADER_SIZE, buffer.c_str(), buffer.size());
m_readPos = MAX_HEADER_SIZE;
m_headerPos = MAX_HEADER_SIZE;
m_messageSize = buffer.size();
}
uint8 InputMessage::getU8(bool peek)
@@ -112,6 +100,25 @@ void InputMessage::decryptRSA(int size, const std::string& p, const std::string&
RSA::decrypt((char*)m_buffer + m_readPos, size, p.c_str(), q.c_str(), d.c_str());
}
void InputMessage::fillBuffer(uint8 *buffer, uint16 size)
{
memcpy(m_buffer + m_readPos, buffer, size);
m_messageSize += size;
}
void InputMessage::setHeaderSize(uint16 size)
{
m_headerPos = MAX_HEADER_SIZE - size;
m_readPos = m_headerPos;
}
bool InputMessage::readChecksum()
{
uint32_t receivedCheck = getU32();
uint32 checksum = Fw::getAdlerChecksum(m_buffer + m_readPos, getUnreadSize());
return receivedCheck == checksum;
}
bool InputMessage::canRead(int bytes)
{
if((m_readPos - m_headerPos + bytes > m_messageSize) || (m_readPos + bytes > BUFFER_MAXSIZE))

View File

@@ -37,6 +37,8 @@ public:
InputMessage();
void setBuffer(const std::string& buffer);
void skipBytes(uint16 bytes) { m_readPos += bytes; }
uint8 getU8(bool peek = false);
uint16 getU16(bool peek = false);
@@ -53,7 +55,6 @@ public:
protected:
void reset();
void fillBuffer(uint8 *buffer, uint16 size);
void setHeaderSize(uint16 size);

View File

@@ -40,6 +40,8 @@ public:
void reset();
std::string getBuffer() { return std::string((char*)m_buffer + m_headerPos, m_messageSize); }
void addU8(uint8 value);
void addU16(uint16 value);
void addU32(uint32 value);