18 #ifndef IGN_TRANSPORT_PACKET_HH_ 19 #define IGN_TRANSPORT_PACKET_HH_ 26 #include "ignition/transport/config.hh" 27 #include "ignition/transport/Export.hh" 35 inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
48 static const uint16_t
FlagRelay = 0b000000000000
'0001; 49 // Flag set when we want to avoid to relay a discovery message. 50 // This is used to avoid loops. 51 static const uint16_t FlagNoRelay = 0b000000000000'0010;
56 "UNINITIALIZED",
"ADVERTISE",
"SUBSCRIBE",
"UNADVERTISE",
"HEARTBEAT",
57 "BYE",
"NEW_CONNECTION",
"END_CONNECTION" 64 class IGNITION_TRANSPORT_VISIBLE
Header 67 public:
Header() =
default;
74 public:
Header(
const uint16_t _version,
77 const uint16_t _flags = 0);
80 public:
virtual ~
Header() =
default;
85 public: uint16_t Version()
const;
95 public: uint8_t Type()
const;
100 public: uint16_t Flags()
const;
105 public:
void SetVersion(
const uint16_t _version);
115 public:
void SetType(
const uint8_t _type);
120 public:
void SetFlags(
const uint16_t _flags);
124 public:
int HeaderLength()
const;
131 public:
size_t Pack(
char *_buffer)
const;
135 public:
size_t Unpack(
const char *_buffer);
143 _out <<
"--------------------------------------\n" 145 <<
"\tVersion: " << _header.
Version() <<
"\n" 146 <<
"\tProcess UUID: " << _header.
PUuid() <<
"\n" 147 <<
"\tType: " << MsgTypesStr.
at(_header.
Type()) <<
"\n" 148 <<
"\tFlags: " << _header.
Flags() <<
"\n";
153 private: uint16_t version = 0;
158 #pragma warning(push) 159 #pragma warning(disable: 4251) 171 private: uint16_t flags = 0;
210 public:
size_t MsgLength()
const;
228 public:
size_t Pack(
char *_buffer)
const;
233 public:
size_t Unpack(
const char *_buffer);
241 #pragma warning(push) 242 #pragma warning(disable: 4251) 269 publisher(_publisher)
286 return this->publisher;
294 this->header = _header;
302 this->publisher = _publisher;
309 return this->header.HeaderLength() + this->publisher.MsgLength();
315 public:
size_t Pack(
char *_buffer)
const 318 size_t len = this->header.Pack(_buffer);
325 if (this->publisher.Pack(_buffer) == 0)
328 return this->MsgLength();
334 public:
size_t Unpack(
const char *_buffer)
337 if (this->publisher.Unpack(_buffer) == 0)
340 return this->publisher.MsgLength();
349 _out << _msg.header << _msg.publisher;
357 private: T publisher;
static const uint16_t FlagRelay
Definition: Packet.hh:48
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:346
friend std::ostream & operator<<(std::ostream &_out, const SubscriptionMsg &_msg)
Stream insertion operator.
Definition: Packet.hh:215
Subscription packet used in the discovery protocol for requesting information about a given topic...
Definition: Packet.hh:177
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:334
static const uint8_t NewConnection
Definition: Packet.hh:44
static const uint8_t HeartbeatType
Definition: Packet.hh:42
static const uint8_t SubType
Definition: Packet.hh:40
static const uint8_t ByeType
Definition: Packet.hh:43
void SetHeader(const transport::Header &_header)
Set the header of the message.
Definition: Packet.hh:292
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:307
static const uint8_t UnadvType
Definition: Packet.hh:41
static const uint8_t EndConnection
Definition: Packet.hh:45
T & Publisher()
Get the publisher of this message.
Definition: Packet.hh:284
transport::Header Header() const
Get the message header.
static const uint8_t AdvType
Definition: Packet.hh:39
Advertise packet used in the discovery protocol to broadcast information about the node advertising a...
Definition: Packet.hh:258
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:300
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:54
static const uint8_t Uninitialized
Definition: Packet.hh:38
AdvertiseMessage(const Header &_header, const T &_publisher)
Constructor.
Definition: Packet.hh:266
Definition: AdvertiseOptions.hh:28
std::string Topic() const
Get the topic.
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:315
transport::Header Header() const
Get the message header.
Definition: Packet.hh:276