Commit 1b2652ee authored by Joseph Noir's avatar Joseph Noir

Add functionality for datagram header

parent b8bb11b5
......@@ -22,17 +22,45 @@
#include <cstdint>
#include "caf/meta/type_name.hpp"
namespace caf {
namespace io {
namespace network {
/// This header adds a sequence number and response port to
/// datagram messages carrying BASP messages.
struct header {
struct datagram_header {
uint32_t sequence_number;
uint16_t response_port;
inline datagram_header(uint32_t seq, uint16_t port)
: sequence_number(seq),
response_port(port) {
// nop
}
datagram_header() = default;
};
/// @relates datagram_header
template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, datagram_header& hdr) {
return f(meta::type_name("datagram_header"), hdr.sequence_number,
hdr.response_port);
}
/// @relates datagram_header
bool operator==(const datagram_header& lhs, const datagram_header& rhs);
/// @relates datagram_header
inline bool operator!=(const datagram_header& lhs, const datagram_header& rhs) {
return !(lhs == rhs);
}
/// Size of the datagram header in serialized form
constexpr size_t datagram_header_size = sizeof(uint32_t) + sizeof(uint16_t);
} // namespace network
} // namespace io
} // namespace caf
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/io/network/datagram_header.hpp"
#include <sstream>
namespace caf {
namespace io {
namespace network {
bool operator==(const datagram_header& lhs, const datagram_header& rhs) {
return lhs.sequence_number == rhs.sequence_number
&& lhs.response_port == rhs.response_port;
}
} // namespace network
} // namespace io
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment