MADARA  3.4.1
MessageHeader.h
Go to the documentation of this file.
1 #ifndef _MADARA_MESSAGE_HEADER_H_
2 #define _MADARA_MESSAGE_HEADER_H_
3 
12 #include "madara/utility/StdInt.h"
13 #include "madara/MadaraExport.h"
14 #include <string>
15 #include <string.h>
16 
17 namespace madara
18 {
19 namespace transport
20 {
21 #define MADARA_IDENTIFIER_LENGTH 8
22 #define MADARA_IDENTIFIER "KaRL1.5"
23 #define MADARA_DOMAIN_MAX_LENGTH 32
24 #define PAIR_COUNT_TYPE uint32_t
25 #define KNOWLEDGE_QUALITY_TYPE uint32_t
26 #define CLOCK_TYPE uint64_t
27 #define MAX_KNOWLEDGE_KEY_LENGTH 64
28 #define MAX_ORIGINATOR_LENGTH 64
29 #define KNOWLEDGE_VALUE_TYPE madara::knowledge::KnowledgeRecord
30 
31 static const int MAX_PACKET_SIZE = 512000; // 512kb
32 
56 class MADARA_EXPORT MessageHeader
57 {
58 public:
62  MessageHeader();
63 
67  virtual ~MessageHeader();
68 
74  virtual uint32_t encoded_size(void) const;
75 
82  static uint32_t static_encoded_size(void);
83 
93  virtual const char* read(const char* buffer, int64_t& buffer_remaining);
94 
104  virtual char* write(char* buffer, int64_t& buffer_remaining);
105 
110  virtual std::string to_string(void);
111 
117  virtual bool equals(const MessageHeader& other);
118 
123  static uint64_t get_size(const char* buffer);
124 
129  static inline bool message_header_test(const char* buffer)
130  {
131  return strncmp(&(buffer[8]), MADARA_IDENTIFIER, 7) == 0;
132  }
133 
137  uint64_t size;
138 
142  char madara_id[MADARA_IDENTIFIER_LENGTH] = {
143  '\0','\0','\0','\0','\0','\0','\0','\0'
144  };
145 
149  char domain[MADARA_DOMAIN_MAX_LENGTH] = {
150  '\0','\0','\0','\0','\0','\0','\0','\0',
151  '\0','\0','\0','\0','\0','\0','\0','\0',
152  '\0','\0','\0','\0','\0','\0','\0','\0',
153  '\0','\0','\0','\0','\0','\0','\0','\0'
154  };
155 
159  char originator[MAX_ORIGINATOR_LENGTH] = {
160  '\0','\0','\0','\0','\0','\0','\0','\0',
161  '\0','\0','\0','\0','\0','\0','\0','\0',
162  '\0','\0','\0','\0','\0','\0','\0','\0',
163  '\0','\0','\0','\0','\0','\0','\0','\0',
164  '\0','\0','\0','\0','\0','\0','\0','\0',
165  '\0','\0','\0','\0','\0','\0','\0','\0',
166  '\0','\0','\0','\0','\0','\0','\0','\0',
167  '\0','\0','\0','\0','\0','\0','\0','\0'
168  };
169 
173  uint32_t type;
174 
178  uint32_t updates;
179 
183  uint32_t quality;
184 
188  uint64_t clock;
189 
193  uint64_t timestamp;
194 
198  unsigned char ttl;
199 };
200 }
201 }
202 
203 #endif // _MADARA_MESSAGE_HEADER_H_
#define MADARA_DOMAIN_MAX_LENGTH
Definition: MessageHeader.h:23
#define MADARA_IDENTIFIER_LENGTH
Definition: MessageHeader.h:21
#define MADARA_IDENTIFIER
Definition: MessageHeader.h:22
#define MAX_ORIGINATOR_LENGTH
Definition: MessageHeader.h:28
Defines a robust message header which is the default for KaRL messages.
Definition: MessageHeader.h:57
uint32_t quality
the quality of the message sender
uint64_t timestamp
the timestamp of the sender when the message was generated
uint32_t updates
the number of knowledge variable updates in the message
uint32_t type
the type of message
static bool message_header_test(const char *buffer)
Tests the buffer for a normal message identifier.
uint64_t clock
the clock of the sender when the message was generated
uint64_t size
the size of this header plus the updates
unsigned char ttl
time to live (number of rebroadcasts to perform after original send
auto get_size(const T &c) -> decltype(c.size())
constexpr string_t string
static const int MAX_PACKET_SIZE
Definition: MessageHeader.h:31
Copyright(c) 2020 Galois.