11 #ifndef PORTHOPPER_PROTOCOL_HPP 12 #define PORTHOPPER_PROTOCOL_HPP 14 #include <boost/array.hpp> 56 std::istrstream is(data_, encoded_port_size);
57 unsigned short port = 0;
58 is >> std::setw(encoded_port_size) >> std::hex >> port;
65 std::istrstream is(data_ + encoded_port_size, encoded_port_size);
66 unsigned short port = 0;
67 is >> std::setw(encoded_port_size) >> std::hex >> port;
82 unsigned short new_port_number)
84 std::ostrstream os(data_, control_request_size);
85 os << std::setw(encoded_port_size) << std::hex << old_port_number;
86 os << std::setw(encoded_port_size) << std::hex << new_port_number;
92 encoded_port_size = 4,
93 control_request_size = encoded_port_size * 2
97 char data_[control_request_size];
105 enum { payload_size = 32 };
113 frame(
unsigned long frame_number,
const std::string& payload_data)
115 std::ostrstream os(data_, frame_size);
116 os << std::setw(encoded_number_size) << std::hex << frame_number;
117 os << std::setw(payload_size)
118 << std::setfill(
' ') << payload_data.substr(0, payload_size);
124 std::istrstream is(data_, encoded_number_size);
125 unsigned long frame_number = 0;
126 is >> std::setw(encoded_number_size) >> std::hex >> frame_number;
133 return std::string(data_ + encoded_number_size, payload_size);
148 encoded_number_size = 8,
149 frame_size = encoded_number_size + payload_size
153 char data_[frame_size];
156 #endif // PORTHOPPER_PROTOCOL_HPP static const control_request change(unsigned short old_port, unsigned short new_port)
static const control_request start(unsigned short port)
static const control_request stop(unsigned short port)
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
const MutableBufferSequence & buffers
frame(unsigned long frame_number, const std::string &payload_data)
const std::string payload() const
boost::array< asio::mutable_buffer, 1 > to_buffers()
unsigned short old_port() const
unsigned long number() const
unsigned short new_port() const
boost::array< asio::mutable_buffer, 1 > to_buffers()