mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:20:05 +00:00
Default ValidateMessage implementation
This commit is contained in:
parent
0303412519
commit
cb86ab4b9b
6 changed files with 59 additions and 48 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include <scwx/wsr88d/message.hpp>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
|
|
@ -20,5 +22,46 @@ Message::~Message() = default;
|
|||
Message::Message(Message&&) noexcept = default;
|
||||
Message& Message::operator=(Message&&) noexcept = default;
|
||||
|
||||
bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const
|
||||
{
|
||||
bool messageValid = true;
|
||||
|
||||
const size_t dataSize = data_size();
|
||||
|
||||
if (is.eof())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of data stream";
|
||||
messageValid = false;
|
||||
}
|
||||
else if (is.fail())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Could not read from input stream";
|
||||
messageValid = false;
|
||||
}
|
||||
else if (bytesRead != dataSize)
|
||||
{
|
||||
is.seekg(static_cast<std::streamoff>(dataSize) -
|
||||
static_cast<std::streamoff>(bytesRead),
|
||||
std::ios_base::cur);
|
||||
|
||||
if (bytesRead < dataSize)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace)
|
||||
<< logPrefix_ << "Message contents smaller than size: " << bytesRead
|
||||
<< " < " << dataSize << " bytes";
|
||||
}
|
||||
if (bytesRead > dataSize)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Message contents larger than size: " << bytesRead
|
||||
<< " > " << dataSize << " bytes";
|
||||
messageValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return messageValid;
|
||||
}
|
||||
|
||||
} // namespace wsr88d
|
||||
} // namespace scwx
|
||||
|
|
|
|||
|
|
@ -29,44 +29,9 @@ Level2Message::~Level2Message() = default;
|
|||
Level2Message::Level2Message(Level2Message&&) noexcept = default;
|
||||
Level2Message& Level2Message::operator=(Level2Message&&) noexcept = default;
|
||||
|
||||
bool Level2Message::ValidateMessage(std::istream& is, size_t bytesRead) const
|
||||
size_t Level2Message::data_size() const
|
||||
{
|
||||
bool messageValid = true;
|
||||
size_t dataSize = header().message_size() * 2 - header().SIZE;
|
||||
|
||||
if (is.eof())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of data stream";
|
||||
messageValid = false;
|
||||
}
|
||||
else if (is.fail())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Could not read from input stream";
|
||||
messageValid = false;
|
||||
}
|
||||
else if (bytesRead != dataSize)
|
||||
{
|
||||
is.seekg(static_cast<std::streamoff>(dataSize) -
|
||||
static_cast<std::streamoff>(bytesRead),
|
||||
std::ios_base::cur);
|
||||
|
||||
if (bytesRead < dataSize)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace)
|
||||
<< logPrefix_ << "Message contents smaller than size: " << bytesRead
|
||||
<< " < " << dataSize << " bytes";
|
||||
}
|
||||
if (bytesRead > dataSize)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Message contents larger than size: " << bytesRead
|
||||
<< " > " << dataSize << " bytes";
|
||||
messageValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return messageValid;
|
||||
return (header().message_size() * 2 - header().SIZE);
|
||||
}
|
||||
|
||||
const Level2MessageHeader& Level2Message::header() const
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@
|
|||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <WinSock2.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
|
|
@ -209,6 +203,11 @@ bool ProductDescriptionBlock::IsCompressionEnabled() const
|
|||
return isCompressed;
|
||||
}
|
||||
|
||||
size_t ProductDescriptionBlock::data_size() const
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
bool ProductDescriptionBlock::Parse(std::istream& is)
|
||||
{
|
||||
bool blockValid = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue