18 #ifndef IGN_TRANSPORT_PACKET_HH_
19 #define IGN_TRANSPORT_PACKET_HH_
46 "UNINITIALIZED",
"ADVERTISE",
"SUBSCRIBE",
"UNADVERTISE",
"HEARTBEAT",
47 "BYE",
"NEW_CONNECTION",
"END_CONNECTION"
57 public:
Header() =
default;
64 public:
Header(
const uint16_t _version,
65 const std::string &_pUuid,
67 const uint16_t _flags = 0);
70 public:
virtual ~
Header() =
default;
75 public: uint16_t Version()
const;
80 public: std::string PUuid()
const;
85 public: uint8_t Type()
const;
90 public: uint16_t Flags()
const;
95 public:
void SetVersion(
const uint16_t _version);
100 public:
void SetPUuid(
const std::string &_pUuid);
105 public:
void SetType(
const uint8_t _type);
110 public:
void SetFlags(
const uint16_t _flags);
114 public:
int HeaderLength()
const;
121 public:
size_t Pack(
char *_buffer)
const;
125 public:
size_t Unpack(
const char *_buffer);
133 _out <<
"--------------------------------------\n"
134 <<
"Header:" << std::endl
135 <<
"\tVersion: " << _header.
Version() <<
"\n"
136 <<
"\tProcess UUID: " << _header.
PUuid() <<
"\n"
138 <<
"\tFlags: " << _header.
Flags() <<
"\n";
143 private: uint16_t version = 0;
146 private: std::string pUuid =
"";
152 private: uint16_t flags = 0;
167 const std::string &_topic);
177 public: std::string Topic()
const;
187 public:
void SetTopic(
const std::string &_topic);
191 public:
size_t MsgLength()
const;
200 <<
"Body:" << std::endl
201 <<
"\tTopic: [" << _msg.
Topic() <<
"]" << std::endl;
209 public:
size_t Pack(
char *_buffer)
const;
214 public:
size_t Unpack(
const char *_buffer);
220 private: std::string topic =
"";
241 publisher(_publisher)
258 return this->publisher;
266 this->header = _header;
274 this->publisher = _publisher;
281 return this->header.HeaderLength() + this->publisher.MsgLength();
287 public:
size_t Pack(
char *_buffer)
const
290 size_t len = this->header.Pack(_buffer);
297 if (this->publisher.Pack(_buffer) == 0)
300 return this->MsgLength();
306 public:
size_t Unpack(
const char *_buffer)
309 if (this->publisher.Unpack(_buffer) == 0)
312 return this->publisher.MsgLength();
321 _out << _msg.header << _msg.publisher;
329 private: T publisher;
std::string Topic() const
Get the topic.
AdvertiseMessage(const Header &_header, const T &_publisher)
Constructor.
Definition: Packet.hh:238
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:318
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:44
friend std::ostream & operator<<(std::ostream &_out, const SubscriptionMsg &_msg)
Stream insertion operator.
Definition: Packet.hh:196
Subscription packet used in the discovery protocol for requesting information about a given topic...
Definition: Packet.hh:158
transport::Header Header() const
Get the message header.
static const uint8_t NewConnection
Definition: Packet.hh:40
static const uint8_t HeartbeatType
Definition: Packet.hh:38
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:287
static const uint8_t ByeType
Definition: Packet.hh:39
static const uint8_t Uninitialized
Definition: Packet.hh:34
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:306
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:272
static const uint8_t EndConnection
Definition: Packet.hh:41
static const uint8_t SubType
Definition: Packet.hh:36
transport::Header Header() const
Get the message header.
Definition: Packet.hh:248
Advertise packet used in the discovery protocol to broadcast information about the node advertising a...
Definition: Packet.hh:230
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:279
static const uint8_t AdvType
Definition: Packet.hh:35
void SetHeader(const transport::Header &_header)
Set the header of the message.
Definition: Packet.hh:264
T & Publisher()
Get the publisher of this message.
Definition: Packet.hh:256
static const uint8_t UnadvType
Definition: Packet.hh:37