Last active
December 23, 2015 18:29
-
-
Save berkus/6675817 to your computer and use it in GitHub Desktop.
Hashmapped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline std::ostream& operator << (std::ostream& os, ssu::base_stream::packet const& pkt) | |
{ | |
static std::unordered_map<stream_protocol::packet_type,std::string> packet_types { | |
{stream_protocol::packet_type::invalid, "invalid"}, | |
{stream_protocol::packet_type::init, "init"}, | |
{stream_protocol::packet_type::reply, "reply"}, | |
{stream_protocol::packet_type::data, "data"}, | |
{stream_protocol::packet_type::datagram, "datagram"}, | |
{stream_protocol::packet_type::ack, "ack"}, | |
{stream_protocol::packet_type::reset, "reset"}, | |
{stream_protocol::packet_type::attach, "attach"}, | |
{stream_protocol::packet_type::detach, "detach"} | |
}; | |
try { | |
packet_type = packet_types.at(pkt.type); | |
} catch(const std::out_of_range&) { | |
packet_type = "unknown"; | |
} | |
os << "[packet txseq " << pkt.tx_byte_seq << ", type " << packet_type | |
<< ", owner " << pkt.owner << ", header " << pkt.header_len | |
<< (pkt.late ? ", late" : ", not late") << ", data " << pkt.buf << "]"; | |
return os; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment