mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 05:10:04 +00:00 
			
		
		
		
	Refactor ScitForecastDataPacket to ScitDataPacket
This commit is contained in:
		
							parent
							
								
									3b110516ed
								
							
						
					
					
						commit
						d92c1e50f2
					
				
					 6 changed files with 128 additions and 137 deletions
				
			
		|  | @ -15,7 +15,7 @@ | |||
| #include <scwx/wsr88d/rpg/precipitation_rate_data_array_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/radial_data_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/raster_data_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/scit_forecast_data_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/scit_data_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/set_color_level_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/sti_circle_symbol_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/storm_id_symbol_packet.hpp> | ||||
|  | @ -63,8 +63,8 @@ static const std::unordered_map<unsigned int, CreateMessageFunction> create_ { | |||
|    {20, PointFeatureSymbolPacket::Create}, | ||||
|    {21, CellTrendDataPacket::Create}, | ||||
|    {22, CellTrendVolumeScanTimes::Create}, | ||||
|    {23, ScitForecastDataPacket::Create}, | ||||
|    {24, ScitForecastDataPacket::Create}, | ||||
|    {23, ScitDataPacket::Create}, | ||||
|    {24, ScitDataPacket::Create}, | ||||
|    {25, StiCircleSymbolPacket::Create}, | ||||
|    {26, PointGraphicSymbolPacket::Create}, | ||||
|    {28, GenericDataPacket::Create}, | ||||
|  |  | |||
							
								
								
									
										80
									
								
								wxdata/source/scwx/wsr88d/rpg/scit_data_packet.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								wxdata/source/scwx/wsr88d/rpg/scit_data_packet.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,80 @@ | |||
| #include <scwx/wsr88d/rpg/scit_data_packet.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <istream> | ||||
| #include <set> | ||||
| #include <string> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace wsr88d | ||||
| { | ||||
| namespace rpg | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::wsr88d::rpg::scit_data_packet"; | ||||
| static const auto        logger_    = util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| static const std::set<std::uint16_t> packetCodes_ = {23, 24}; | ||||
| 
 | ||||
| class ScitDataPacket::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl() : data_ {}, recordCount_ {0} {} | ||||
|    ~Impl() = default; | ||||
| 
 | ||||
|    std::vector<std::uint8_t> data_; | ||||
|    size_t                    recordCount_; | ||||
| }; | ||||
| 
 | ||||
| ScitDataPacket::ScitDataPacket() : p(std::make_unique<Impl>()) {} | ||||
| ScitDataPacket::~ScitDataPacket() = default; | ||||
| 
 | ||||
| ScitDataPacket::ScitDataPacket(ScitDataPacket&&) noexcept            = default; | ||||
| ScitDataPacket& ScitDataPacket::operator=(ScitDataPacket&&) noexcept = default; | ||||
| 
 | ||||
| const std::vector<std::uint8_t>& ScitDataPacket::data() const | ||||
| { | ||||
|    return p->data_; | ||||
| } | ||||
| 
 | ||||
| size_t ScitDataPacket::RecordCount() const | ||||
| { | ||||
|    return p->recordCount_; | ||||
| } | ||||
| 
 | ||||
| bool ScitDataPacket::ParseData(std::istream& is) | ||||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    if (!packetCodes_.contains(packet_code())) | ||||
|    { | ||||
|       logger_->warn("Invalid packet code: {}", packet_code()); | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       p->recordCount_ = length_of_block(); | ||||
|       p->data_.resize(p->recordCount_); | ||||
|       is.read(reinterpret_cast<char*>(p->data_.data()), p->recordCount_); | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<ScitDataPacket> ScitDataPacket::Create(std::istream& is) | ||||
| { | ||||
|    std::shared_ptr<ScitDataPacket> packet = std::make_shared<ScitDataPacket>(); | ||||
| 
 | ||||
|    if (!packet->Parse(is)) | ||||
|    { | ||||
|       packet.reset(); | ||||
|    } | ||||
| 
 | ||||
|    return packet; | ||||
| } | ||||
| 
 | ||||
| } // namespace rpg
 | ||||
| } // namespace wsr88d
 | ||||
| } // namespace scwx
 | ||||
|  | @ -1,88 +0,0 @@ | |||
| #include <scwx/wsr88d/rpg/scit_forecast_data_packet.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <istream> | ||||
| #include <set> | ||||
| #include <string> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace wsr88d | ||||
| { | ||||
| namespace rpg | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = | ||||
|    "scwx::wsr88d::rpg::scit_forecast_data_packet"; | ||||
| static const auto logger_ = util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| static const std::set<uint16_t> packetCodes_ = {23, 24}; | ||||
| 
 | ||||
| class ScitForecastDataPacketImpl | ||||
| { | ||||
| public: | ||||
|    explicit ScitForecastDataPacketImpl() : data_ {}, recordCount_ {0} {} | ||||
|    ~ScitForecastDataPacketImpl() = default; | ||||
| 
 | ||||
|    std::vector<uint8_t> data_; | ||||
|    size_t               recordCount_; | ||||
| }; | ||||
| 
 | ||||
| ScitForecastDataPacket::ScitForecastDataPacket() : | ||||
|     p(std::make_unique<ScitForecastDataPacketImpl>()) | ||||
| { | ||||
| } | ||||
| ScitForecastDataPacket::~ScitForecastDataPacket() = default; | ||||
| 
 | ||||
| ScitForecastDataPacket::ScitForecastDataPacket( | ||||
|    ScitForecastDataPacket&&) noexcept = default; | ||||
| ScitForecastDataPacket& | ||||
| ScitForecastDataPacket::operator=(ScitForecastDataPacket&&) noexcept = default; | ||||
| 
 | ||||
| const std::vector<uint8_t>& ScitForecastDataPacket::data() const | ||||
| { | ||||
|    return p->data_; | ||||
| } | ||||
| 
 | ||||
| size_t ScitForecastDataPacket::RecordCount() const | ||||
| { | ||||
|    return p->recordCount_; | ||||
| } | ||||
| 
 | ||||
| bool ScitForecastDataPacket::ParseData(std::istream& is) | ||||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    if (!packetCodes_.contains(packet_code())) | ||||
|    { | ||||
|       logger_->warn("Invalid packet code: {}", packet_code()); | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       p->recordCount_ = length_of_block(); | ||||
|       p->data_.resize(p->recordCount_); | ||||
|       is.read(reinterpret_cast<char*>(p->data_.data()), p->recordCount_); | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<ScitForecastDataPacket> | ||||
| ScitForecastDataPacket::Create(std::istream& is) | ||||
| { | ||||
|    std::shared_ptr<ScitForecastDataPacket> packet = | ||||
|       std::make_shared<ScitForecastDataPacket>(); | ||||
| 
 | ||||
|    if (!packet->Parse(is)) | ||||
|    { | ||||
|       packet.reset(); | ||||
|    } | ||||
| 
 | ||||
|    return packet; | ||||
| } | ||||
| 
 | ||||
| } // namespace rpg
 | ||||
| } // namespace wsr88d
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat