18 #ifndef IGN_TRANSPORT_PACKET_HH_ 19 #define IGN_TRANSPORT_PACKET_HH_ 26 #include "ignition/transport/config.hh" 27 #include "ignition/transport/Export.hh" 38 inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
51 static const uint16_t
FlagRelay = 0b000000000000
'0001; 52 // Flag set when we want to avoid to relay a discovery message. 53 // This is used to avoid loops. 54 static const uint16_t FlagNoRelay = 0b000000000000'0010;
59 "UNINITIALIZED",
"ADVERTISE",
"SUBSCRIBE",
"UNADVERTISE",
"HEARTBEAT",
60 "BYE",
"NEW_CONNECTION",
"END_CONNECTION" 69 class IGNITION_TRANSPORT_VISIBLE
Header 72 public: IGN_DEPRECATED(8)
Header() =
default;
79 public: IGN_DEPRECATED(8)
Header(
const uint16_t _version,
82 const uint16_t _flags = 0);
85 public:
virtual ~
Header() =
default;
90 public: uint16_t Version()
const;
100 public: uint8_t Type()
const;
105 public: uint16_t Flags()
const;
110 public:
void SetVersion(
const uint16_t _version);
120 public:
void SetType(
const uint8_t _type);
125 public:
void SetFlags(
const uint16_t _flags);
129 public:
int HeaderLength()
const;
136 public:
size_t Pack(
char *_buffer)
const;
140 public:
size_t Unpack(
const char *_buffer);
148 _out <<
"--------------------------------------\n" 150 <<
"\tVersion: " << _header.
Version() <<
"\n" 151 <<
"\tProcess UUID: " << _header.
PUuid() <<
"\n" 152 <<
"\tType: " << MsgTypesStr.
at(_header.
Type()) <<
"\n" 153 <<
"\tFlags: " << _header.
Flags() <<
"\n";
158 private: uint16_t version = 0;
163 #pragma warning(push) 164 #pragma warning(disable: 4251) 176 private: uint16_t flags = 0;
218 public:
size_t MsgLength()
const;
236 public:
size_t Pack(
char *_buffer)
const;
241 public:
size_t Unpack(
const char *_buffer);
248 #pragma warning(push) 249 #pragma warning(disable: 4251) 277 publisher(_publisher)
294 return this->publisher;
302 this->header = _header;
310 this->publisher = _publisher;
317 return this->header.HeaderLength() + this->publisher.MsgLength();
323 public:
size_t Pack(
char *_buffer)
const 326 size_t len = this->header.Pack(_buffer);
333 if (this->publisher.Pack(_buffer) == 0)
336 return this->MsgLength();
342 public:
size_t Unpack(
const char *_buffer)
345 if (this->publisher.Unpack(_buffer) == 0)
348 return this->publisher.MsgLength();
355 this->publisher.SetFromDiscovery(_msg);
364 _out << _msg.header << _msg.publisher;
372 private: T publisher;
static const uint16_t FlagRelay
Definition: Packet.hh:51
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:361
friend std::ostream & operator<<(std::ostream &_out, const SubscriptionMsg &_msg)
Stream insertion operator.
Definition: Packet.hh:223
Subscription packet used in the discovery protocol for requesting information about a given topic...
Definition: Packet.hh:184
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:342
static const uint8_t NewConnection
Definition: Packet.hh:47
static const uint8_t HeartbeatType
Definition: Packet.hh:45
static const uint8_t SubType
Definition: Packet.hh:43
static const uint8_t ByeType
Definition: Packet.hh:46
void SetHeader(const transport::Header &_header)
Set the header of the message.
Definition: Packet.hh:300
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:315
static const uint8_t UnadvType
Definition: Packet.hh:44
static const uint8_t EndConnection
Definition: Packet.hh:48
T & Publisher()
Get the publisher of this message.
Definition: Packet.hh:292
transport::Header Header() const
Get the message header.
static const uint8_t AdvType
Definition: Packet.hh:42
Advertise packet used in the discovery protocol to broadcast information about the node advertising a...
Definition: Packet.hh:266
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:308
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:57
static const uint8_t Uninitialized
Definition: Packet.hh:41
void SetFromDiscovery(const msgs::Discovery &_msg)
Set from discovery message.
Definition: Packet.hh:353
Definition: AdvertiseOptions.hh:28
std::string Topic() const
Get the topic.
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:323
transport::Header Header() const
Get the message header.
Definition: Packet.hh:284