MADARA  3.1.8
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/MADARA_export.h"
14 #include <string>
15 
16 namespace madara
17 {
18  namespace transport
19  {
20  #define MADARA_IDENTIFIER_LENGTH 8
21  #define MADARA_IDENTIFIER "KaRL1.3"
22  #define MADARA_DOMAIN_MAX_LENGTH 32
23  #define PAIR_COUNT_TYPE uint32_t
24  #define KNOWLEDGE_QUALITY_TYPE uint32_t
25  #define CLOCK_TYPE uint64_t
26  #define MAX_KNOWLEDGE_KEY_LENGTH 64
27  #define MAX_ORIGINATOR_LENGTH 64
28  #define KNOWLEDGE_VALUE_TYPE madara::knowledge::KnowledgeRecord
29 
30  static const int MAX_PACKET_SIZE = 512000; // 512kb
31 
32 
56  class MADARA_Export MessageHeader
57  {
58  public:
59 
63  MessageHeader ();
64 
68  virtual ~MessageHeader ();
69 
75  virtual uint32_t encoded_size (void) const;
76 
83  static uint32_t static_encoded_size (void);
84 
93  virtual const char * read (const char * buffer,
94  int64_t & buffer_remaining);
95 
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 
148 
152  char originator[MAX_ORIGINATOR_LENGTH];
153 
157  uint32_t type;
158 
162  uint32_t updates;
163 
167  uint32_t quality;
168 
172  uint64_t clock;
173 
177  uint64_t timestamp;
178 
182  unsigned char ttl;
183  };
184  }
185 }
186 
187 
188 #endif // _MADARA_MESSAGE_HEADER_H_
#define MADARA_IDENTIFIER
Definition: MessageHeader.h:21
uint32_t updates
the number of knowledge variable updates in the message
#define MAX_ORIGINATOR_LENGTH
Definition: MessageHeader.h:27
uint32_t type
the type of message
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
static const int MAX_PACKET_SIZE
Definition: MessageHeader.h:30
uint64_t timestamp
the timestamp of the sender when the message was generated
static constexpr struct madara::knowledge::tags::string_t string
static bool message_header_test(const char *buffer)
Tests the buffer for a normal message identifier.
#define MADARA_IDENTIFIER_LENGTH
Definition: MessageHeader.h:20
uint64_t clock
the clock of the sender when the message was generated
#define MADARA_DOMAIN_MAX_LENGTH
Definition: MessageHeader.h:22
Copyright (c) 2015 Carnegie Mellon University.
Defines a robust message header which is the default for KaRL messages.
Definition: MessageHeader.h:56
uint32_t quality
the quality of the message sender