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;
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,
80 const
std::
string &_pUuid,
82 const uint16_t _flags = 0);
90 public: uint16_t Version() const;
95 public:
std::
string PUuid() const;
100 public: uint8_t Type() const;
105 public: uint16_t Flags() const;
110 public:
void SetVersion(const uint16_t _version);
115 public:
void SetPUuid(const
std::
string &_pUuid);
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);
145 public: friend
std::ostream &operator<<(
std::ostream &_out,
148 _out <<
"--------------------------------------\n"
150 <<
"\tVersion: " << _header.Version() <<
"\n"
151 <<
"\tProcess UUID: " << _header.PUuid() <<
"\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;
193 const transport::
Header &_header,
194 const
std::
string &_topic);
204 public:
std::
string Topic() const;
209 public:
void SetHeader(const transport::
Header &_header);
214 public:
void SetTopic(const
std::
string &_topic);
218 public:
size_t MsgLength() const;
223 public: friend
std::ostream &operator<<(
std::ostream &_out,
226 _out << _msg.Header()
228 <<
"\tTopic: [" << _msg.Topic() <<
"]" <<
std::endl;
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;
Advertise packet used in the discovery protocol to broadcast information about the node advertising a...
Definition: Packet.hh:267
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:315
void SetFromDiscovery(const msgs::Discovery &_msg)
Set from discovery message.
Definition: Packet.hh:353
void SetHeader(const transport::Header &_header)
Set the header of the message.
Definition: Packet.hh:300
transport::Header Header() const
Get the message header.
Definition: Packet.hh:284
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:361
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:323
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:342
T & Publisher()
Get the publisher of this message.
Definition: Packet.hh:292
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:308
Subscription packet used in the discovery protocol for requesting information about a given topic.
Definition: Packet.hh:185
size_t Pack(char *_buffer) const
Serialize the subscription message.
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into a Sub.
static const uint8_t ByeType
Definition: Packet.hh:46
static const uint8_t EndConnection
Definition: Packet.hh:48
static const uint8_t Uninitialized
Definition: Packet.hh:41
static const uint8_t UnadvType
Definition: Packet.hh:44
static const uint8_t SubType
Definition: Packet.hh:43
static const uint16_t FlagRelay
Definition: Packet.hh:51
static const uint16_t FlagNoRelay
Definition: Packet.hh:54
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:57
static const uint8_t HeartbeatType
Definition: Packet.hh:45
static const uint8_t NewConnection
Definition: Packet.hh:47
static const uint8_t AdvType
Definition: Packet.hh:42
Definition: AdvertiseOptions.hh:29