MADARA  3.1.8
Fragmentation.h
Go to the documentation of this file.
1 #ifndef _MADARA_FRAGMENTATION_HEADER_H_
2 #define _MADARA_FRAGMENTATION_HEADER_H_
3 
13 #include <map>
14 #include <string>
15 #include "madara/utility/stdint.h"
16 #include "madara/MADARA_export.h"
18 
19 namespace madara
20 {
21  namespace transport
22  {
23  #define FRAGMENTATION_MADARA_ID "KFRG1.3"
24 
47  class MADARA_Export FragmentMessageHeader : public MessageHeader
48  {
49  public:
50 
55 
59  virtual ~FragmentMessageHeader ();
60 
66  virtual uint32_t encoded_size (void) const;
67 
73  static uint32_t static_encoded_size (void);
74 
79  static uint32_t get_updates (const char * buffer);
80 
89  virtual const char * read (const char * buffer,
90  int64_t & buffer_remaining);
91 
95  void operator= (MessageHeader & header);
96 
105  virtual char * write (char * buffer, int64_t & buffer_remaining);
106 
112  virtual bool equals (const MessageHeader & other);
113 
118  static inline bool fragment_message_header_test (const char * buffer)
119  {
120  return strncmp (&(buffer[8]), FRAGMENTATION_MADARA_ID, 7) == 0;
121  }
122 
123  uint32_t update_number;
124  };
125 
129  typedef std::map <uint32_t, const char *> FragmentMap;
130 
134  typedef std::map <uint64_t, FragmentMap> ClockFragmentMap;
135 
139  typedef std::map <
140  std::string, ClockFragmentMap> OriginatorFragmentMap;
141 
156  MADARA_Export char * add_fragment (const char * originator, uint64_t clock,
157  uint32_t update_number, const char * fragment,
158  uint32_t queue_length,
159  OriginatorFragmentMap & map, bool clear = true);
160 
167  MADARA_Export char * defrag (FragmentMap & map);
168 
173  MADARA_Export void delete_fragments (FragmentMap & map);
174 
181  MADARA_Export void frag (
182  char * source, uint32_t fragment_size, FragmentMap & map);
183 
191  MADARA_Export bool is_complete (const char * originator, uint64_t clock,
192  OriginatorFragmentMap & map);
193 
202  MADARA_Export bool exists (const char * originator, uint64_t clock,
203  uint32_t update_number, OriginatorFragmentMap & map);
204  }
205 }
206 
207 #endif // _MADARA_FRAGMENTATION_HEADER_H_
MADARA_Export char * add_fragment(const char *originator, uint64_t clock, uint32_t update_number, const char *fragment, uint32_t queue_length, OriginatorFragmentMap &map, bool clear=true)
Adds a fragment to an originator fragment map and returns the aggregate message if the message is com...
MADARA_Export char * defrag(FragmentMap &map)
Pieces together a fragment map into a single buffer.
MADARA_Export bool is_complete(const char *originator, uint64_t clock, OriginatorFragmentMap &map)
Breaks a large packet into smaller packets.
MADARA_Export void frag(char *source, uint32_t fragment_size, FragmentMap &map)
Breaks a large packet into smaller packets.
#define FRAGMENTATION_MADARA_ID
Definition: Fragmentation.h:23
Defines a fragmentation header which allows for multi-part messages that are only applied once all fr...
Definition: Fragmentation.h:47
static bool fragment_message_header_test(const char *buffer)
Tests the buffer for a reduced message identifier.
std::map< std::string, ClockFragmentMap > OriginatorFragmentMap
Map of originator to a map of clocks to fragments.
std::map< uint64_t, FragmentMap > ClockFragmentMap
Map of clocks to fragments.
static constexpr struct madara::knowledge::tags::string_t string
MADARA_Export void delete_fragments(FragmentMap &map)
Deletes fragments within a fragment map and clears the map.
MADARA_Export bool exists(const char *originator, uint64_t clock, uint32_t update_number, OriginatorFragmentMap &map)
Checks if a fragment already exists within a fragment map.
std::map< uint32_t, const char * > FragmentMap
Map of fragment identifiers to fragments.
Copyright (c) 2015 Carnegie Mellon University.
Defines a robust message header which is the default for KaRL messages.
Definition: MessageHeader.h:56