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 {
50 "UNINITIALIZED",
"ADVERTISE",
"SUBSCRIBE",
"UNADVERTISE",
"HEARTBEAT",
51 "BYE",
"NEW_CONNECTION",
"END_CONNECTION" 58 class IGNITION_TRANSPORT_VISIBLE
Header 61 public:
Header() =
default;
68 public:
Header(
const uint16_t _version,
71 const uint16_t _flags = 0);
74 public:
virtual ~
Header() =
default;
79 public: uint16_t Version()
const;
89 public: uint8_t Type()
const;
94 public: uint16_t Flags()
const;
99 public:
void SetVersion(
const uint16_t _version);
109 public:
void SetType(
const uint8_t _type);
114 public:
void SetFlags(
const uint16_t _flags);
118 public:
int HeaderLength()
const;
125 public:
size_t Pack(
char *_buffer)
const;
129 public:
size_t Unpack(
const char *_buffer);
137 _out <<
"--------------------------------------\n" 139 <<
"\tVersion: " << _header.
Version() <<
"\n" 140 <<
"\tProcess UUID: " << _header.
PUuid() <<
"\n" 141 <<
"\tType: " << MsgTypesStr.
at(_header.
Type()) <<
"\n" 142 <<
"\tFlags: " << _header.
Flags() <<
"\n";
147 private: uint16_t version = 0;
152 #pragma warning(push) 153 #pragma warning(disable: 4251) 165 private: uint16_t flags = 0;
204 public:
size_t MsgLength()
const;
222 public:
size_t Pack(
char *_buffer)
const;
227 public:
size_t Unpack(
const char *_buffer);
235 #pragma warning(push) 236 #pragma warning(disable: 4251) 263 publisher(_publisher)
280 return this->publisher;
288 this->header = _header;
296 this->publisher = _publisher;
303 return this->header.HeaderLength() + this->publisher.MsgLength();
309 public:
size_t Pack(
char *_buffer)
const 312 size_t len = this->header.Pack(_buffer);
319 if (this->publisher.Pack(_buffer) == 0)
322 return this->MsgLength();
328 public:
size_t Unpack(
const char *_buffer)
331 if (this->publisher.Unpack(_buffer) == 0)
334 return this->publisher.MsgLength();
343 _out << _msg.header << _msg.publisher;
351 private: T publisher;
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessage &_msg)
Stream insertion operator.
Definition: Packet.hh:340
friend std::ostream & operator<<(std::ostream &_out, const SubscriptionMsg &_msg)
Stream insertion operator.
Definition: Packet.hh:209
Subscription packet used in the discovery protocol for requesting information about a given topic...
Definition: Packet.hh:171
size_t Unpack(const char *_buffer)
Unserialize a stream of bytes into an AdvertiseMessage.
Definition: Packet.hh:328
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:286
size_t MsgLength() const
Get the total length of the message.
Definition: Packet.hh:301
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:278
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:252
void SetPublisher(const T &_publisher)
Set the publisher of this message.
Definition: Packet.hh:294
static const std::vector< std::string > MsgTypesStr
Used for debugging the message type received/send.
Definition: Packet.hh:48
static const uint8_t Uninitialized
Definition: Packet.hh:38
AdvertiseMessage(const Header &_header, const T &_publisher)
Constructor.
Definition: Packet.hh:260
Definition: AdvertiseOptions.hh:28
std::string Topic() const
Get the topic.
size_t Pack(char *_buffer) const
Serialize the advertise message.
Definition: Packet.hh:309
transport::Header Header() const
Get the message header.
Definition: Packet.hh:270