18 #ifndef __IGN_TRANSPORT_PACKET_HH_INCLUDED__ 19 #define __IGN_TRANSPORT_PACKET_HH_INCLUDED__ 49 "UNINITIALIZED",
"ADVERTISE",
"SUBSCRIBE",
"UNADVERTISE",
"HEARTBEAT",
50 "BYE",
"ADV_SRV",
"SUB_SRV",
"UNADVERTISE_SRV",
"NEW_CONNECTION",
61 public:
Header() =
default;
69 public:
Header(
const uint16_t _version,
70 const std::string &_pUuid,
72 const uint16_t _flags = 0);
75 public:
virtual ~
Header() =
default;
80 public: uint16_t Version()
const;
85 public: std::string PUuid()
const;
90 public: uint8_t Type()
const;
95 public: uint16_t Flags()
const;
100 public:
void SetVersion(
const uint16_t _version);
105 public:
void SetPUuid(
const std::string &_pUuid);
110 public:
void SetType(
const uint8_t _type);
115 public:
void SetFlags(
const uint16_t _flags);
119 public:
int HeaderLength()
const;
126 public:
size_t Pack(
char *_buffer)
const;
130 public:
size_t Unpack(
const char *_buffer);
138 _out <<
"--------------------------------------\n" 139 <<
"Header:" << std::endl
140 <<
"\tVersion: " << _header.
Version() <<
"\n" 141 <<
"\tProcess UUID: " << _header.
PUuid() <<
"\n" 142 <<
"\tType: " << MsgTypesStr.at(_header.
Type()) <<
"\n" 143 <<
"\tFlags: " << _header.
Flags() <<
"\n";
148 private: uint16_t version = 0;
151 private: std::string pUuid =
"";
157 private: uint16_t flags = 0;
172 const std::string &_topic);
182 public: std::string Topic()
const;
192 public:
void SetTopic(
const std::string &_topic);
196 public:
size_t MsgLength()
const;
205 <<
"Body:" << std::endl
206 <<
"\tTopic: [" << _msg.
Topic() <<
"]" << std::endl;
214 public:
size_t Pack(
char *_buffer)
const;
219 public:
size_t Unpack(
char *_buffer);
225 private: std::string topic =
"";
246 publisher(_publisher)
263 return this->publisher;
271 this->header = _header;
279 this->publisher = _publisher;
286 return this->header.HeaderLength() + this->publisher.MsgLength();
292 public:
size_t Pack(
char *_buffer)
const 295 size_t len = this->header.Pack(_buffer);
302 if (this->publisher.Pack(_buffer) == 0)
305 return this->MsgLength();
314 if (this->publisher.Unpack(_buffer) == 0)
317 return this->publisher.MsgLength();
326 _out << _msg.header << _msg.publisher;
334 private: T publisher;
std::string Topic() const
Get the topic.
static const uint8_t AdvSrvType
Definition: Packet.hh:40
AdvertiseMessage(const Header &_header, const T &_publisher)
Constructor.
Definition: Packet.hh:243
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:323
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:47
friend std::ostream & operator<<(std::ostream &_out, const SubscriptionMsg &_msg)
Stream insertion operator.
Definition: Packet.hh:201
Subscription packet used in the discovery protocol for requesting information about a given topic...
Definition: Packet.hh:163
transport::Header Header() const
Get the message header.
static const uint8_t NewConnection
Definition: Packet.hh:43
static const uint8_t HeartbeatType
Definition: Packet.hh:38
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:292
static const uint8_t ByeType
Definition: Packet.hh:39
static const uint8_t Uninitialized
Definition: Packet.hh:34
size_t Unpack(char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:311
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:277
static const uint8_t EndConnection
Definition: Packet.hh:44
static const uint8_t UnadvSrvType
Definition: Packet.hh:42
static const uint8_t SubType
Definition: Packet.hh:36
transport::Header Header() const
Get the message header.
Definition: Packet.hh:253
Advertise packet used in the discovery protocol to broadcast information about the node advertising a...
Definition: Packet.hh:235
static const uint8_t SubSrvType
Definition: Packet.hh:41
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:284
Definition: AdvertiseOptions.hh:25
static const uint8_t AdvType
Definition: Packet.hh:35
void SetHeader(const transport::Header &_header)
Set the header of the message.
Definition: Packet.hh:269
T & Publisher()
Get the publisher of this message.
Definition: Packet.hh:261
static const uint8_t UnadvType
Definition: Packet.hh:37