MADARA  3.2.3
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.3"
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 
33 
57  class MADARA_EXPORT MessageHeader
58  {
59  public:
60 
64  MessageHeader ();
65 
69  virtual ~MessageHeader ();
70 
76  virtual uint32_t encoded_size (void) const;
77 
84  static uint32_t static_encoded_size (void);
85 
95  virtual const char * read (const char * buffer,
96  int64_t & buffer_remaining);
97 
107  virtual char * write (char * buffer, int64_t & buffer_remaining);
108 
113  virtual std::string to_string (void);
114 
120  virtual bool equals (const MessageHeader & other);
121 
126  static uint64_t get_size (const char * buffer);
127 
132  static inline bool message_header_test (const char * buffer)
133  {
134  return strncmp (&(buffer[8]), MADARA_IDENTIFIER, 7) == 0;
135  }
136 
140  uint64_t size;
141 
145  char madara_id[MADARA_IDENTIFIER_LENGTH];
146 
151 
155  char originator[MAX_ORIGINATOR_LENGTH];
156 
160  uint32_t type;
161 
165  uint32_t updates;
166 
170  uint32_t quality;
171 
175  uint64_t clock;
176 
180  uint64_t timestamp;
181 
185  unsigned char ttl;
186  };
187  }
188 }
189 
190 
191 #endif // _MADARA_MESSAGE_HEADER_H_
#define MADARA_IDENTIFIER
Definition: MessageHeader.h:22
uint32_t updates
the number of knowledge variable updates in the message
#define MAX_ORIGINATOR_LENGTH
Definition: MessageHeader.h:28
uint32_t type
the type of message
static struct madara::knowledge::tags::string_t string
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:31
uint64_t timestamp
the timestamp of the sender when the message was generated
static bool message_header_test(const char *buffer)
Tests the buffer for a normal message identifier.
#define MADARA_IDENTIFIER_LENGTH
Definition: MessageHeader.h:21
uint64_t clock
the clock of the sender when the message was generated
#define MADARA_DOMAIN_MAX_LENGTH
Definition: MessageHeader.h:23
Copyright (c) 2015 Carnegie Mellon University.
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