fipa_acl  1.4
Public Member Functions | List of all members
fipa::acl::BitefficientMessageFormat Class Reference

#include <bitefficient_message_format.h>

Inherits fipa::acl::MessageFormat.

Public Member Functions

virtual ~BitefficientMessageFormat ()
 
std::string apply (const ACLMessage &msg) const
 
std::string getBitAID (const AgentID &aid, int depth) const
 encodes an AgentID instance More...
 
std::string getBitHeader () const
 puts the header toghether More...
 
char getBitMessageID () const
 depending on the flags it sets the ID More...
 
char getBitMessageVersion () const
 gets the message version in one byte the message version has a very specific format: digit+dot+digit More...
 
std::string getBitMessageType (const ACLMessage &msg) const
 encodes the message performative; it compares the string of the message performative to all the predefined ones; if it is one of them it returns accordingly if not it returns the custom performative More...
 
std::string getBitBinWord (const std::string &sword) const
 quite frequently used production; currently it does not have complete functionality: the code tables need to be implemented in order to use them More...
 
std::string getBitMessageParameters (const ACLMessage &msg) const
 puts together all the message parameters More...
 
std::string getBitPredefMessageParams (const ACLMessage &msg) const
 checks all predefined message parameters whether they are set or not and it encodes them accordingly More...
 
std::string getBitUserdefMessageParams (const ACLMessage &msg) const
 
std::string getBitUserdefParams (const std::vector< UserdefParam > &params) const
 parses a set of user defined parameters; different from the getBitUserdefMessageParams() method in that there is more general; the former is to be called only for message parameters; difference was imposed by the specification More...
 
std::string bitParseParam (const UserdefParam &) const
 parses one user defined parameter the specification does not differentiate at this level between message parameters and other kinds so this method is called by both More...
 
std::string getBinURLCol (const std::vector< std::string > &) const
 currently used to encode the addresses of the AgentID instances(strings) More...
 
std::string getBitResolvers (const std::vector< AgentID > &aids, int depth) const
 basically a wrapper function of the getBitAIDColl(), to add the required specific flag More...
 
std::string getBitAIDColl (const std::vector< AgentID > &aids, int depth) const
 parses a set of AgentID instances the resolvers depth variable that is being passed around is not modified in this function More...
 
std::string getBitBinExpression (const std::string &sword, char c) const
 implements the binary expression production of the grammar; not complete(w.r.t. the specification) in functionality implementing the messages without the rest of the architecture makes it difficult to anticipate when and how some productions may/will be used so only a few of the productions were implemented(for the binary expression) and the char parameter was added to choose between them, as no other decission maker/constraint was identified More...
 
std::string getBitBinExpression (double n, char base) const
 overloaded version of the above function More...
 
std::string getBitBinNumber (double n, char base) const
 parses a number according to the specification(see comment 9 of the specification) for ease it is turned into a string and passed on More...
 
std::string getByteLengthEncodedString (const std::string &sword) const
 
std::string getBitBinString (const std::string &sword) const
 implements the binary string production; functionality not complete as code tables are not yet implemented the second argument is an explicit option for codeTables(needed for the getBitBinExpression() ) More...
 
std::string getBitDigits (const std::string &dig) const
 
- Public Member Functions inherited from fipa::acl::MessageFormat
 MessageFormat ()
 
virtual ~MessageFormat ()
 
void setUseCodeTables (bool x)
 
bool getUseCodeTables () const
 
void setUpdateCodeTables (bool x)
 
bool getUpdateCodeTables () const
 
void setResolverDepth (int depth)
 
int getResolverDepth () const
 
void setVersion (const std::string &version)
 
std::string getVersion () const
 

Detailed Description

Definition at line 9 of file bitefficient_message_format.h.

Constructor & Destructor Documentation

◆ ~BitefficientMessageFormat()

virtual fipa::acl::BitefficientMessageFormat::~BitefficientMessageFormat ( )
inlinevirtual

Definition at line 12 of file bitefficient_message_format.h.

12 {}

Member Function Documentation

◆ apply()

std::string fipa::acl::BitefficientMessageFormat::apply ( const ACLMessage msg) const
virtual

Applies the format to the message

Returns
the formatted message object

Implements fipa::acl::MessageFormat.

Definition at line 25 of file bitefficient_message_format.cpp.

26 {
27  std::string mes = getBitHeader() + getBitMessageType(msg) + getBitMessageParameters(msg);
28 
29  // Since content can be of arbitrary sicne add content here
30  // to avoid copying around large content object
31  const std::string* content = msg.getContentPtr();
32  if (!content->empty())
33  {
34  uint32_t digit = content->size();
35  mes += 0x04;
36 
37  // Check if there is binary content to be set
38  // add choose encoding based on the respective content size
39  if(strlen(content->c_str()) != digit)
40  {
41  if(digit <= std::numeric_limits<uint8_t>::max())
42  {
43  uint8_t dataSize = digit;
44  mes += 0x16;
45  mes.append(reinterpret_cast<const char*>(&dataSize), sizeof(uint8_t));
46  mes += *content;
47  } else if (digit <= std::numeric_limits<uint16_t>::max())
48  {
49  uint16_t dataSize = digit;
50  dataSize = htons(dataSize);
51  mes += 0x17;
52  mes.append(reinterpret_cast<const char*>(&dataSize),sizeof(uint16_t));
53  mes += *content;
54  } else {
55  digit = htonl(digit);
56  mes += 0x19;
57  mes.append(reinterpret_cast<const char*>(&digit),sizeof(uint32_t));
58  mes += *content;
59  }
60  } else { // use string with null terminated (more efficient)
61  char digitString[100];
62  snprintf(digitString,100, "%c#%d%c",0x14,digit,'\"');
63  mes += digitString;
64  mes += *content;
65  mes += char(0x00);
66  }
67  }
68 
70  return mes;
71 }
std::string getBitMessageParameters(const ACLMessage &msg) const
puts together all the message parameters
std::string getBitMessageType(const ACLMessage &msg) const
encodes the message performative; it compares the string of the message performative to all the prede...
static char getEOFCollection()
returns the very used end-of-collection marker
std::string getBitHeader() const
puts the header toghether

◆ bitParseParam()

std::string fipa::acl::BitefficientMessageFormat::bitParseParam ( const UserdefParam p) const

parses one user defined parameter the specification does not differentiate at this level between message parameters and other kinds so this method is called by both

Definition at line 244 of file bitefficient_message_format.cpp.

245 {
246  return getBitBinWord(p.getName()) + getBitBinExpression(p.getValue(),'s');
247 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
std::string getBitBinExpression(const std::string &sword, char c) const
implements the binary expression production of the grammar; not complete(w.r.t. the specification) in...

◆ getBinURLCol()

std::string fipa::acl::BitefficientMessageFormat::getBinURLCol ( const std::vector< std::string > &  adrr) const

currently used to encode the addresses of the AgentID instances(strings)

Definition at line 267 of file bitefficient_message_format.cpp.

268 {
269  std::string retstr;
270  std::vector<std::string>::const_iterator it = adrr.begin();
271  for (; it != adrr.end(); ++it)
272  retstr = retstr + getBitBinWord(*it);
273 
274  retstr = retstr + BitefficientFormat::getEOFCollection();
275  return retstr;
276 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
static char getEOFCollection()
returns the very used end-of-collection marker

◆ getBitAID()

std::string fipa::acl::BitefficientMessageFormat::getBitAID ( const AgentID aid,
int  depth 
) const

encodes an AgentID instance

as some fields are optional the method first checks for their existance it also keeps record of the res_depth

Parameters
aidAgentID object pointer to be encoded
depthdepth of the resolver tree to be encoded
Returns
the encoded agentAID as string

Definition at line 250 of file bitefficient_message_format.cpp.

251 {
252  if (depth > 0)
253  return char(0x02) + getBitBinWord(aid.getName())+
254  (( aid.getAddresses().empty() == true)? "" : (char(0x02) + getBinURLCol(aid.getAddresses()))) +
255  (( aid.getResolvers().empty() == true)? "" : getBitResolvers(aid.getResolvers(),depth-1)) +
256  (( aid.getUserdefParams().empty() == true)? "" : getBitUserdefParams(aid.getUserdefParams())) +
258 
259 
260  return char(0x02) + getBitBinWord(aid.getName())+
261  (( aid.getAddresses().empty() == true)? "" : (char(0x02) + getBinURLCol(aid.getAddresses()))) +
262  (( aid.getUserdefParams().empty() == true)? "" : getBitUserdefParams(aid.getUserdefParams())) +
264 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
std::string getBitUserdefParams(const std::vector< UserdefParam > &params) const
parses a set of user defined parameters; different from the getBitUserdefMessageParams() method in th...
std::string getBinURLCol(const std::vector< std::string > &) const
currently used to encode the addresses of the AgentID instances(strings)
static char getEOFCollection()
returns the very used end-of-collection marker
std::string getBitResolvers(const std::vector< AgentID > &aids, int depth) const
basically a wrapper function of the getBitAIDColl(), to add the required specific flag ...

◆ getBitAIDColl()

std::string fipa::acl::BitefficientMessageFormat::getBitAIDColl ( const std::vector< AgentID > &  aids,
int  depth 
) const

parses a set of AgentID instances the resolvers depth variable that is being passed around is not modified in this function

Definition at line 283 of file bitefficient_message_format.cpp.

284 {
285  std::string retstr;
286  std::vector<AgentID>::const_iterator it = aids.begin();
287  for (; it != aids.end(); ++it)
288  retstr = retstr + getBitAID(*it, depth);
289  return retstr + BitefficientFormat::getEOFCollection();
290 }
std::string getBitAID(const AgentID &aid, int depth) const
encodes an AgentID instance
static char getEOFCollection()
returns the very used end-of-collection marker

◆ getBitBinExpression() [1/2]

std::string fipa::acl::BitefficientMessageFormat::getBitBinExpression ( const std::string &  sword,
char  c 
) const

implements the binary expression production of the grammar; not complete(w.r.t. the specification) in functionality implementing the messages without the rest of the architecture makes it difficult to anticipate when and how some productions may/will be used so only a few of the productions were implemented(for the binary expression) and the char parameter was added to choose between them, as no other decission maker/constraint was identified

Definition at line 297 of file bitefficient_message_format.cpp.

298 {
299  //if (!sword.compare(msg.getContent()))
300  //{
301  // return char(0xff) + getBitBinString(sword);
302  //}
303 
304  if (c == 's')
305  return getBitBinString(sword);
306 
307  if (c == 'w')
308  return getBitBinWord(sword);
309 
310  throw std::runtime_error("BitefficientMessageFormat: getBitBinExpression called with wrong base character");
311 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
std::string getBitBinString(const std::string &sword) const
implements the binary string production; functionality not complete as code tables are not yet implem...

◆ getBitBinExpression() [2/2]

std::string fipa::acl::BitefficientMessageFormat::getBitBinExpression ( double  n,
char  base 
) const

overloaded version of the above function

Definition at line 313 of file bitefficient_message_format.cpp.

314 {
315  return getBitBinNumber(n,base);
316 }
std::string getBitBinNumber(double n, char base) const
parses a number according to the specification(see comment 9 of the specification) for ease it is tur...

◆ getBitBinNumber()

std::string fipa::acl::BitefficientMessageFormat::getBitBinNumber ( double  n,
char  base 
) const

parses a number according to the specification(see comment 9 of the specification) for ease it is turned into a string and passed on

Definition at line 318 of file bitefficient_message_format.cpp.

319 {
320  std::stringstream ss (std::stringstream::in | std::stringstream::out);
321  ss << n;
322  std::string test = ss.str();
323 
324  if(base == 'h')
325  return char(0x13) + BitefficientFormat::getDigits(test);
326  if(base == 'o' || base == 'd')
327  return char(0x12) + BitefficientFormat::getDigits(test);
328 
329  throw std::runtime_error("BitefficientMessageFormat: getBitBinNumber called with wrong base character");
330 }
static std::string getDigits(const std::string &numberString)

◆ getBitBinString()

std::string fipa::acl::BitefficientMessageFormat::getBitBinString ( const std::string &  sword) const

implements the binary string production; functionality not complete as code tables are not yet implemented the second argument is an explicit option for codeTables(needed for the getBitBinExpression() )

Definition at line 332 of file bitefficient_message_format.cpp.

333 {
334  if (!getUseCodeTables())
335  {
336  return char(0x14) + ( '\"' + sword + '\"') + char(0x00);
337  }
338  // char(0x15) + return getCTIndex(sword);
339  throw std::runtime_error("BitefficientMessageFormat does not support codetables");
340 
341 }
bool getUseCodeTables() const

◆ getBitBinWord()

std::string fipa::acl::BitefficientMessageFormat::getBitBinWord ( const std::string &  sword) const

quite frequently used production; currently it does not have complete functionality: the code tables need to be implemented in order to use them

Definition at line 124 of file bitefficient_message_format.cpp.

125 {
126  if (!getUseCodeTables())
127  {
128  return (char(0x10) + sword + char(0x00));
129  }
130 
131  throw std::runtime_error("BitefficientMessageFormat does not support codetables");
132 }
bool getUseCodeTables() const

◆ getBitDigits()

std::string fipa::acl::BitefficientMessageFormat::getBitDigits ( const std::string &  dig) const

Get bitefficient representation of digits

◆ getBitHeader()

std::string fipa::acl::BitefficientMessageFormat::getBitHeader ( ) const

puts the header toghether

Definition at line 73 of file bitefficient_message_format.cpp.

74 {
75  std::string retstr;
76 
77  char id = getBitMessageID();
78  char version = getBitMessageVersion();
79 
80  return retstr.append(1,id).append(1,version);
81 }
char getBitMessageVersion() const
gets the message version in one byte the message version has a very specific format: digit+dot+digit ...
char getBitMessageID() const
depending on the flags it sets the ID

◆ getBitMessageID()

char fipa::acl::BitefficientMessageFormat::getBitMessageID ( ) const

depending on the flags it sets the ID

Definition at line 83 of file bitefficient_message_format.cpp.

84 {
85  if (!getUseCodeTables())
86  {
87  return 0xfa;
88  }
89  if (getUpdateCodeTables())
90  {
91  return 0xfb;
92  }
93  return 0xfc;
94 }
bool getUpdateCodeTables() const
bool getUseCodeTables() const

◆ getBitMessageParameters()

std::string fipa::acl::BitefficientMessageFormat::getBitMessageParameters ( const ACLMessage msg) const

puts together all the message parameters

Definition at line 134 of file bitefficient_message_format.cpp.

135 {
137 }
std::string getBitUserdefMessageParams(const ACLMessage &msg) const
std::string getBitPredefMessageParams(const ACLMessage &msg) const
checks all predefined message parameters whether they are set or not and it encodes them accordingly ...

◆ getBitMessageType()

std::string fipa::acl::BitefficientMessageFormat::getBitMessageType ( const ACLMessage msg) const

encodes the message performative; it compares the string of the message performative to all the predefined ones; if it is one of them it returns accordingly if not it returns the custom performative

Definition at line 102 of file bitefficient_message_format.cpp.

103 {
104  std::string performative = msg.getPerformative();
105  // Check if we have one of the predefined performatives
106  for (int i = (int) ACLMessage::ACCEPT_PROPOSAL; i < (int) ACLMessage::END_PERFORMATIVE; ++i)
107  {
108  if (PerformativeTxt[(ACLMessage::Performative) i] == performative)
109  {
110  char a[2];
111  a[0] = char(i+1);
112  a[1] = '\0';
113  return std::string(a);
114  }
115  }
116 
117  // actually we will have user defined performative here
118  if(performative.empty())
119  throw MessageGeneratorException("Performative cannot be empty");
120 
121  return (char(0x00) + getBitBinWord(performative));
122 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
Performative
an enum of all the predefined fipa message performatives so far, presented in the order used in the m...
Definition: acl_message.h:64
std::map< ACLMessage::Performative, std::string > PerformativeTxt
Definition: acl_message.cpp:15

◆ getBitMessageVersion()

char fipa::acl::BitefficientMessageFormat::getBitMessageVersion ( ) const

gets the message version in one byte the message version has a very specific format: digit+dot+digit

Definition at line 96 of file bitefficient_message_format.cpp.

97 {
98  std::string version = getVersion();
99  return char(((int) version[0]-48)*16 + ((int)version[2]-48));
100 }
std::string getVersion() const

◆ getBitPredefMessageParams()

std::string fipa::acl::BitefficientMessageFormat::getBitPredefMessageParams ( const ACLMessage msg) const

checks all predefined message parameters whether they are set or not and it encodes them accordingly

Content added at higher level to minimize copies of large content objects

Definition at line 141 of file bitefficient_message_format.cpp.

142 {
143  std::string retstr;
144 
145  // Check if entries exists for the predefined message parameters
146  // sender is not always required,
147  AgentID sender = msg.getSender();
148  if ( !sender.empty())
149  {
150  LOG_DEBUG("Writing sender: %s", getBitAID(sender, getResolverDepth()).c_str());
151  retstr = retstr + char(0x02) + getBitAID(sender, getResolverDepth());
152  }
153 
154  std::vector<AgentID> receivers = msg.getAllReceivers();
155  if (!receivers.empty())
156  {
157  retstr = retstr + char(0x03) + getBitAIDColl(receivers,getResolverDepth());
158  }
159 
161 
162  std::string replyWith = msg.getReplyWith();
163  if (!replyWith.empty())
164  retstr = retstr + char(0x05) + getBitBinExpression(replyWith,'s');
165 
166  if (!msg.getReplyBy().isNull())
167  {
168  retstr = retstr + char(0x06) + BitefficientFormat::getBinDateTimeToken(msg.getReplyBy());
169  }
170 
171  std::string inReplyTo = msg.getInReplyTo();
172  if (!inReplyTo.empty())
173  {
174  retstr = retstr + char(0x07) + getBitBinExpression(inReplyTo,'s');
175  }
176 
177  std::vector<AgentID> replyTo = msg.getAllReplyTo();
178  if (!replyTo.empty())
179  {
180  retstr = retstr + char(0x08) + getBitAIDColl(replyTo,getResolverDepth());
181  }
182 
183  std::string language = msg.getLanguage();
184  if (!language.empty())
185  {
186  retstr = retstr + char(0x09) + getBitBinExpression(language,'s');
187  }
188 
189  std::string encoding = msg.getEncoding();
190  if (!encoding.empty())
191  {
192  retstr = retstr + char(0x0a) + getBitBinExpression(encoding,'s');
193  }
194 
195  std::string ontology = msg.getOntology();
196  if (!ontology.empty())
197  retstr = retstr + char(0x0b) + getBitBinExpression(ontology,'s');
198 
199  std::string protocol = msg.getProtocol();
200  if (!protocol.empty())
201  {
202  retstr = retstr + char(0x0c) + getBitBinWord(protocol);
203  }
204 
205  std::string conversationID = msg.getConversationID();
206  if (!conversationID.empty())
207  retstr = retstr + char(0x0d) + getBitBinExpression(conversationID,'s');
208 
209  return retstr;
210 }
std::string getBitBinWord(const std::string &sword) const
quite frequently used production; currently it does not have complete functionality: the code tables ...
std::string getBitAIDColl(const std::vector< AgentID > &aids, int depth) const
parses a set of AgentID instances the resolvers depth variable that is being passed around is not mod...
std::string getBitBinExpression(const std::string &sword, char c) const
implements the binary expression production of the grammar; not complete(w.r.t. the specification) in...
std::string getBitAID(const AgentID &aid, int depth) const
encodes an AgentID instance
static std::string getBinDateTimeToken(const std::string &date1)
implements the date time token production of the grammar; not complete(w.r.t. the specification) in f...

◆ getBitResolvers()

std::string fipa::acl::BitefficientMessageFormat::getBitResolvers ( const std::vector< AgentID > &  aids,
int  depth 
) const

basically a wrapper function of the getBitAIDColl(), to add the required specific flag

Definition at line 278 of file bitefficient_message_format.cpp.

279 {
280  return (char(0x03) + getBitAIDColl(aids,depth));
281 }
std::string getBitAIDColl(const std::vector< AgentID > &aids, int depth) const
parses a set of AgentID instances the resolvers depth variable that is being passed around is not mod...

◆ getBitUserdefMessageParams()

std::string fipa::acl::BitefficientMessageFormat::getBitUserdefMessageParams ( const ACLMessage msg) const

parses all the user defined parameters of the message if any

Definition at line 212 of file bitefficient_message_format.cpp.

213 {
214  std::string retstr;
215 
216  std::vector<UserdefParam> s = msg.getUserdefParams();
217  if( s.empty() )
218  {
219  return retstr;
220  }
221 
222  LOG_WARN("Userdefined parameters: %d", (int) s.size());
223 
224  std::vector<UserdefParam>::iterator it;
225  it = s.begin();
226  for (; it != s.end(); ++it)
227  {
228  retstr = retstr + char(0x00) + bitParseParam(*it);
229  }
230 
231  return retstr;
232 }
std::string bitParseParam(const UserdefParam &) const
parses one user defined parameter the specification does not differentiate at this level between mess...

◆ getBitUserdefParams()

std::string fipa::acl::BitefficientMessageFormat::getBitUserdefParams ( const std::vector< UserdefParam > &  params) const

parses a set of user defined parameters; different from the getBitUserdefMessageParams() method in that there is more general; the former is to be called only for message parameters; difference was imposed by the specification

Definition at line 234 of file bitefficient_message_format.cpp.

235 {
236  std::string retstr;
237  std::vector<UserdefParam>::const_iterator it = params.begin();
238  for (; it != params.end(); ++it)
239  retstr = retstr + char(0x04) + bitParseParam(*it);
240 
241  return retstr;
242 }
std::string bitParseParam(const UserdefParam &) const
parses one user defined parameter the specification does not differentiate at this level between mess...

◆ getByteLengthEncodedString()

std::string fipa::acl::BitefficientMessageFormat::getByteLengthEncodedString ( const std::string &  sword) const

Retrieve the byte length encoded string for the given word

Parameters
swordString containing the data to convert

Definition at line 292 of file bitefficient_message_format.cpp.

293 {
294  return char(0x14) + BitefficientFormat::getByteLengthEncodedString(sword) + char(0x00);
295 }
static std::string getByteLengthEncodedString(const std::string &sword)

The documentation for this class was generated from the following files: