Add to_string functions to the classes asc_pull_req and asc_pull_ack (#4255)
Adding ::to_string methods to asc_pull_req and asc_pull_ack messages.
This commit is contained in:
		
					parent
					
						
							
								da9cf6ac00
							
						
					
				
			
			
				commit
				
					
						b7dc1da699
					
				
			
		
					 2 changed files with 73 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -23,7 +23,9 @@
 | 
			
		|||
#include <sstream>
 | 
			
		||||
#include <stdexcept>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
#include <utility>
 | 
			
		||||
#include <variant>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -1656,6 +1658,35 @@ bool nano::asc_pull_req::verify_consistency () const
 | 
			
		|||
	return true; // Just for convenience of calling from asserts
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string nano::asc_pull_req::to_string () const
 | 
			
		||||
{
 | 
			
		||||
	std::string s = header.to_string () + "\n";
 | 
			
		||||
 | 
			
		||||
	std::visit ([&s] (auto && arg) {
 | 
			
		||||
		using T = std::decay_t<decltype (arg)>;
 | 
			
		||||
 | 
			
		||||
		if constexpr (std::is_same_v<T, nano::empty_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			s += "missing payload";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		else if constexpr (std::is_same_v<T, nano::asc_pull_req::blocks_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			s += "acc:" + arg.start.to_string ();
 | 
			
		||||
			s += " max block count:" + to_string_hex (static_cast<uint16_t> (arg.count));
 | 
			
		||||
			s += " hash type:" + to_string_hex (static_cast<uint16_t> (arg.start_type));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		else if constexpr (std::is_same_v<T, nano::asc_pull_req::account_info_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			s += "target:" + arg.target.to_string ();
 | 
			
		||||
			s += " hash type:" + to_string_hex (static_cast<uint16_t> (arg.target_type));
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	payload);
 | 
			
		||||
 | 
			
		||||
	return s;
 | 
			
		||||
}
 | 
			
		||||
/*
 | 
			
		||||
 * asc_pull_req::blocks_payload
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -1809,6 +1840,45 @@ bool nano::asc_pull_ack::verify_consistency () const
 | 
			
		|||
	return true; // Just for convenience of calling from asserts
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string nano::asc_pull_ack::to_string () const
 | 
			
		||||
{
 | 
			
		||||
	std::string s = header.to_string () + "\n";
 | 
			
		||||
 | 
			
		||||
	std::visit ([&s] (auto && arg) {
 | 
			
		||||
		using T = std::decay_t<decltype (arg)>;
 | 
			
		||||
 | 
			
		||||
		if constexpr (std::is_same_v<T, nano::empty_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			s += "missing payload";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		else if constexpr (std::is_same_v<T, nano::asc_pull_ack::blocks_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			auto block = std::begin (arg.blocks);
 | 
			
		||||
			auto end_block = std::end (arg.blocks);
 | 
			
		||||
 | 
			
		||||
			while (block != end_block)
 | 
			
		||||
			{
 | 
			
		||||
				s += (*block)->to_json ();
 | 
			
		||||
				++block;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		else if constexpr (std::is_same_v<T, nano::asc_pull_ack::account_info_payload>)
 | 
			
		||||
		{
 | 
			
		||||
			s += "account public key:" + arg.account.to_account ();
 | 
			
		||||
			s += " account open:" + arg.account_open.to_string ();
 | 
			
		||||
			s += " account head:" + arg.account_head.to_string ();
 | 
			
		||||
			s += " block count:" + to_string_hex (arg.account_block_count);
 | 
			
		||||
			s += " confirmation frontier:" + arg.account_conf_frontier.to_string ();
 | 
			
		||||
			s += " confirmation height:" + to_string_hex (arg.account_conf_height);
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	payload);
 | 
			
		||||
 | 
			
		||||
	return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * asc_pull_ack::blocks_payload
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -429,6 +429,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	void serialize_payload (nano::stream &) const;
 | 
			
		||||
	void deserialize_payload (nano::stream &);
 | 
			
		||||
	std::string to_string () const;
 | 
			
		||||
 | 
			
		||||
private: // Debug
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -504,6 +505,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	void serialize_payload (nano::stream &) const;
 | 
			
		||||
	void deserialize_payload (nano::stream &);
 | 
			
		||||
	std::string to_string () const;
 | 
			
		||||
 | 
			
		||||
private: // Debug
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -613,4 +615,4 @@ public:
 | 
			
		|||
	}
 | 
			
		||||
	virtual void default_handler (nano::message const &){};
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue