mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 08:10:04 +00:00
Level2MessageFactory clang-tidy cleanup
This commit is contained in:
parent
f709380a97
commit
926cce1eac
2 changed files with 27 additions and 43 deletions
|
|
@ -2,28 +2,19 @@
|
||||||
|
|
||||||
#include <scwx/wsr88d/rda/level2_message.hpp>
|
#include <scwx/wsr88d/rda/level2_message.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx::wsr88d::rda
|
||||||
{
|
|
||||||
namespace wsr88d
|
|
||||||
{
|
|
||||||
namespace rda
|
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Level2MessageInfo
|
struct Level2MessageInfo
|
||||||
{
|
{
|
||||||
std::shared_ptr<Level2Message> message;
|
std::shared_ptr<Level2Message> message {nullptr};
|
||||||
bool headerValid;
|
bool headerValid {false};
|
||||||
bool messageValid;
|
bool messageValid {false};
|
||||||
|
|
||||||
Level2MessageInfo() :
|
|
||||||
message(nullptr), headerValid(false), messageValid(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Level2MessageFactory
|
class Level2MessageFactory
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
explicit Level2MessageFactory() = delete;
|
explicit Level2MessageFactory() = delete;
|
||||||
~Level2MessageFactory() = delete;
|
~Level2MessageFactory() = delete;
|
||||||
|
|
||||||
|
|
@ -33,7 +24,6 @@ private:
|
||||||
Level2MessageFactory(Level2MessageFactory&&) noexcept = delete;
|
Level2MessageFactory(Level2MessageFactory&&) noexcept = delete;
|
||||||
Level2MessageFactory& operator=(Level2MessageFactory&&) noexcept = delete;
|
Level2MessageFactory& operator=(Level2MessageFactory&&) noexcept = delete;
|
||||||
|
|
||||||
public:
|
|
||||||
struct Context;
|
struct Context;
|
||||||
|
|
||||||
static std::shared_ptr<Context> CreateContext();
|
static std::shared_ptr<Context> CreateContext();
|
||||||
|
|
@ -41,6 +31,4 @@ public:
|
||||||
std::shared_ptr<Context>& ctx);
|
std::shared_ptr<Context>& ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rda
|
} // namespace scwx::wsr88d::rda
|
||||||
} // namespace wsr88d
|
|
||||||
} // namespace scwx
|
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,16 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx::wsr88d::rda
|
||||||
{
|
|
||||||
namespace wsr88d
|
|
||||||
{
|
|
||||||
namespace rda
|
|
||||||
{
|
{
|
||||||
|
|
||||||
static const std::string logPrefix_ =
|
static const std::string logPrefix_ =
|
||||||
"scwx::wsr88d::rda::level2_message_factory";
|
"scwx::wsr88d::rda::level2_message_factory";
|
||||||
static const auto logger_ = util::Logger::Create(logPrefix_);
|
static const auto logger_ = util::Logger::Create(logPrefix_);
|
||||||
|
|
||||||
typedef std::function<std::shared_ptr<Level2Message>(Level2MessageHeader&&,
|
using CreateLevel2MessageFunction =
|
||||||
std::istream&)>
|
std::function<std::shared_ptr<Level2Message>(Level2MessageHeader&&,
|
||||||
CreateLevel2MessageFunction;
|
std::istream&)>;
|
||||||
|
|
||||||
static const std::unordered_map<unsigned int, CreateLevel2MessageFunction>
|
static const std::unordered_map<unsigned int, CreateLevel2MessageFunction>
|
||||||
create_ {{1, DigitalRadarData::Create},
|
create_ {{1, DigitalRadarData::Create},
|
||||||
|
|
@ -44,15 +40,12 @@ static const std::unordered_map<unsigned int, CreateLevel2MessageFunction>
|
||||||
struct Level2MessageFactory::Context
|
struct Level2MessageFactory::Context
|
||||||
{
|
{
|
||||||
Context() :
|
Context() :
|
||||||
messageData_ {},
|
messageBuffer_ {messageData_}, messageBufferStream_ {&messageBuffer_}
|
||||||
bufferedSize_ {},
|
|
||||||
messageBuffer_ {messageData_},
|
|
||||||
messageBufferStream_ {&messageBuffer_}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> messageData_;
|
std::vector<char> messageData_ {};
|
||||||
size_t bufferedSize_;
|
std::size_t bufferedSize_ {};
|
||||||
util::vectorbuf messageBuffer_;
|
util::vectorbuf messageBuffer_;
|
||||||
std::istream messageBufferStream_;
|
std::istream messageBufferStream_;
|
||||||
bool bufferingData_ {false};
|
bool bufferingData_ {false};
|
||||||
|
|
@ -78,13 +71,16 @@ Level2MessageInfo Level2MessageFactory::Create(std::istream& is,
|
||||||
|
|
||||||
if (info.headerValid)
|
if (info.headerValid)
|
||||||
{
|
{
|
||||||
if (header.message_size() == 65535)
|
if (header.message_size() == std::numeric_limits<std::uint16_t>::max())
|
||||||
{
|
{
|
||||||
|
// A message size of 65535 indicates a message with a single segment.
|
||||||
|
// The size is specified in the bytes normally reserved for the segment
|
||||||
|
// number and total number of segments.
|
||||||
segment = 1;
|
segment = 1;
|
||||||
totalSegments = 1;
|
totalSegments = 1;
|
||||||
dataSize =
|
dataSize =
|
||||||
(static_cast<std::size_t>(header.number_of_message_segments())
|
(static_cast<std::size_t>(header.number_of_message_segments())
|
||||||
<< 16) +
|
<< 16) + // NOLINT(cppcoreguidelines-avoid-magic-numbers)
|
||||||
header.message_segment_number();
|
header.message_segment_number();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -145,14 +141,16 @@ Level2MessageInfo Level2MessageFactory::Create(std::istream& is,
|
||||||
logger_->debug("Bad size estimate, increasing size");
|
logger_->debug("Bad size estimate, increasing size");
|
||||||
|
|
||||||
// Estimate remaining size
|
// Estimate remaining size
|
||||||
uint16_t remainingSegments =
|
static const std::uint16_t kMinRemainingSegments_ = 100u;
|
||||||
std::max<uint16_t>(totalSegments - segment + 1, 100u);
|
std::uint16_t remainingSegments = std::max<std::uint16_t>(
|
||||||
size_t remainingSize = remainingSegments * dataSize;
|
totalSegments - segment + 1, kMinRemainingSegments_);
|
||||||
|
std::size_t remainingSize = remainingSegments * dataSize;
|
||||||
|
|
||||||
ctx->messageData_.resize(ctx->bufferedSize_ + remainingSize);
|
ctx->messageData_.resize(ctx->bufferedSize_ + remainingSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
is.read(ctx->messageData_.data() + ctx->bufferedSize_, dataSize);
|
is.read(&ctx->messageData_[ctx->bufferedSize_],
|
||||||
|
static_cast<std::streamsize>(dataSize));
|
||||||
ctx->bufferedSize_ += dataSize;
|
ctx->bufferedSize_ += dataSize;
|
||||||
|
|
||||||
if (is.eof())
|
if (is.eof())
|
||||||
|
|
@ -166,7 +164,7 @@ Level2MessageInfo Level2MessageFactory::Create(std::istream& is,
|
||||||
else if (segment == totalSegments)
|
else if (segment == totalSegments)
|
||||||
{
|
{
|
||||||
ctx->messageBuffer_.update_read_pointers(ctx->bufferedSize_);
|
ctx->messageBuffer_.update_read_pointers(ctx->bufferedSize_);
|
||||||
header.set_message_size(static_cast<uint16_t>(
|
header.set_message_size(static_cast<std::uint16_t>(
|
||||||
ctx->bufferedSize_ / 2 + Level2MessageHeader::SIZE));
|
ctx->bufferedSize_ / 2 + Level2MessageHeader::SIZE));
|
||||||
|
|
||||||
messageStream = &ctx->messageBufferStream_;
|
messageStream = &ctx->messageBufferStream_;
|
||||||
|
|
@ -188,7 +186,7 @@ Level2MessageInfo Level2MessageFactory::Create(std::istream& is,
|
||||||
else if (info.headerValid)
|
else if (info.headerValid)
|
||||||
{
|
{
|
||||||
// Seek to the end of the current message
|
// Seek to the end of the current message
|
||||||
is.seekg(dataSize, std::ios_base::cur);
|
is.seekg(static_cast<std::streamoff>(dataSize), std::ios_base::cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.message == nullptr)
|
if (info.message == nullptr)
|
||||||
|
|
@ -199,6 +197,4 @@ Level2MessageInfo Level2MessageFactory::Create(std::istream& is,
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rda
|
} // namespace scwx::wsr88d::rda
|
||||||
} // namespace wsr88d
|
|
||||||
} // namespace scwx
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue