mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:00:04 +00:00 
			
		
		
		
	Refactoring generic message components to awips namespace
This commit is contained in:
		
							parent
							
								
									a76103650e
								
							
						
					
					
						commit
						7a9582a689
					
				
					 14 changed files with 64 additions and 65 deletions
				
			
		
							
								
								
									
										67
									
								
								wxdata/source/scwx/awips/message.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								wxdata/source/scwx/awips/message.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| #include <scwx/awips/message.hpp> | ||||
| 
 | ||||
| #include <boost/log/trivial.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace awips | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "[scwx::awips::message] "; | ||||
| 
 | ||||
| class MessageImpl | ||||
| { | ||||
| public: | ||||
|    explicit MessageImpl() {}; | ||||
|    ~MessageImpl() = default; | ||||
| }; | ||||
| 
 | ||||
| Message::Message() : p(std::make_unique<MessageImpl>()) {} | ||||
| 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 awips
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat