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

#include <bitefficient_format.h>

Static Public Member Functions

static char getEOFCollection ()
 returns the very used end-of-collection marker More...
 
static char getEOFEnvelope ()
 
static std::string getByteLengthEncodedString (const std::string &sword)
 
static std::string getNullTerminatedString (const std::string &sword)
 
static std::string getString (const std::string &sword)
 
static std::string getCodedNumber (const std::string &cn)
 implements a coded number passed as a string it goes through it digit by digit(char by char) More...
 
static std::string getCodedNaturalNumber (const std::string &cn)
 Allow proper generation of natural numbers, will remove any leading zeros. More...
 
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 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 and the char parameter was added to choose between them, as no other decission maker/constraint was identified More...
 
static std::string getBinDateTimeToken (const base::Time &time)
 implements the date time token 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 and the char parameter was added to choose between them, as no other decission maker/constraint was identified More...
 
static std::string getBinDate (const base::Time &time)
 
static std::string getBinDate (const std::string &date1)
 takes the string representing the date and passes it's digits 2 by 2(as length 2 sugstrings) to the byte encoding function it did not explicitly specify but it was induced from the way it was stated that the date is to be encoded as a coded number(comment 9 of the specification) More...
 
static std::string getBinNumber (uint32_t number, bool asHex=false)
 
static std::string getACLRepresentation (const representation::Type &type)
 
static std::string getDigits (const std::string &numberString)
 
static std::string getDigits (uint32_t number)
 
static std::string getReceivedObject (const ReceivedObject &object)
 
static std::string getAgentID (const AgentID &agentId)
 
static std::string getAgentIDSequence (const std::vector< AgentID > &agentIds)
 
static std::string getBinStringNoCodetable (const std::string &sword)
 

Detailed Description

Definition at line 13 of file bitefficient_format.h.

Member Function Documentation

std::string fipa::acl::BitefficientFormat::getACLRepresentation ( const representation::Type type)
static

Encode representation

Definition at line 176 of file bitefficient_format.cpp.

177 {
178  std::string msg = "";
179  switch(type)
180  {
182  msg += char(0x10); break;
184  msg += char(0x11); break;
185  case representation::XML:
186  msg += char(0x12); break;
187  default:
188  throw std::runtime_error("BitefficientFormat: Cannot encode unknown acl representation");
189  }
190 
191  return msg;
192 }
std::string fipa::acl::BitefficientFormat::getAgentID ( const AgentID agentId)
static

Retrieve encoded agent id for envelopes

Definition at line 231 of file bitefficient_format.cpp.

232 {
233  std::string agentIdString = char(0x02) + getNullTerminatedString(agentId.getName());
234  // addresses (optional)
235  {
236  const Addresses& addresses = agentId.getAddresses();
237  if(!addresses.empty())
238  {
239  Addresses::const_iterator cit = addresses.begin();
240  agentIdString += char(0x02);
241  for(; cit != addresses.end(); ++cit)
242  {
243  agentIdString += getNullTerminatedString(*cit);
244  }
245  agentIdString += getEOFCollection();
246  }
247  }
248  // resolvers(optional)
249  {
250  const Resolvers& resolvers = agentId.getResolvers();
251  if(!resolvers.empty())
252  {
253  Resolvers::const_iterator cit = resolvers.begin();
254  agentIdString += char(0x03);
255  for(; cit != resolvers.end(); ++cit)
256  {
257  agentIdString += getAgentID(*cit);
258  }
259  agentIdString += getEOFCollection();
260  }
261  }
262  // userdefined parameters
263  {
264  const UserdefinedParameterList& userdefParams = agentId.getUserdefParams();
265  if(!userdefParams.empty())
266  {
267  UserdefinedParameterList::const_iterator cit = userdefParams.begin();
268  for(; cit != userdefParams.end(); ++cit)
269  {
270  agentIdString += char(0x05);
271  agentIdString += getNullTerminatedString(cit->getName());
272  agentIdString += getBinStringNoCodetable(cit->getValue());
273  }
274  }
275  }
276  agentIdString += getEOFCollection();
277  return agentIdString;
278 }
static std::string getNullTerminatedString(const std::string &sword)
std::vector< UserdefParam > UserdefinedParameterList
Definition: userdef_param.h:94
AgentIDList Resolvers
Definition: agent_id.h:27
static std::string getAgentID(const AgentID &agentId)
std::vector< std::string > Addresses
Definition: agent_id.h:28
static char getEOFCollection()
returns the very used end-of-collection marker
static std::string getBinStringNoCodetable(const std::string &sword)
std::string fipa::acl::BitefficientFormat::getAgentIDSequence ( const std::vector< AgentID > &  agentIds)
static

Get sequence of agents ids

Definition at line 280 of file bitefficient_format.cpp.

281 {
282  std::vector<AgentID>::const_iterator cit = agentIds.begin();
283  std::string sequence;
284  for(;cit != agentIds.end(); ++cit)
285  {
286  sequence += getAgentID(*cit);
287  }
288  sequence += getEOFCollection();
289  return sequence;
290 }
static std::string getAgentID(const AgentID &agentId)
static char getEOFCollection()
returns the very used end-of-collection marker
std::string fipa::acl::BitefficientFormat::getBinDate ( const base::Time &  time)
static

Retrieve bitefficient encoding for base time

Definition at line 39 of file bitefficient_format.cpp.

40 {
41 
42  std::string time = baseTime.toString(base::Time::Milliseconds);
43 
44  // Input format should be "%Y%m%d-%H:%M:%S"
45  // Strip ':' and '-' to allow from_iso_string to work
46  boost::erase_all(time,":");
47  boost::erase_all(time,"-");
48 
49  // extend millisecond field to 4 digits
50  time.insert(14,sizeof(char),'0');
51 
52  return getBinDate(time);
53 }
static std::string getBinDate(const base::Time &time)
std::string fipa::acl::BitefficientFormat::getBinDate ( const std::string &  date1)
static

takes the string representing the date and passes it's digits 2 by 2(as length 2 sugstrings) to the byte encoding function it did not explicitly specify but it was induced from the way it was stated that the date is to be encoded as a coded number(comment 9 of the specification)

Definition at line 55 of file bitefficient_format.cpp.

56 {
57  std::string retstr;
58  unsigned int i;
59  for (i = 0; i < date1.length(); i = i + 2)
60  {
61  retstr = retstr + getCodedNaturalNumber(date1.substr(i,2));
62  }
63 
64  return retstr;
65 }
static std::string getCodedNaturalNumber(const std::string &cn)
Allow proper generation of natural numbers, will remove any leading zeros.
std::string fipa::acl::BitefficientFormat::getBinDateTimeToken ( const std::string &  date1)
static

implements the date time token 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 and the char parameter was added to choose between them, as no other decission maker/constraint was identified

Definition at line 29 of file bitefficient_format.cpp.

30 {
31  return char(0x20) + getBinDate(date1);
32 }
static std::string getBinDate(const base::Time &time)
std::string fipa::acl::BitefficientFormat::getBinDateTimeToken ( const base::Time &  time)
static

implements the date time token 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 and the char parameter was added to choose between them, as no other decission maker/constraint was identified

Definition at line 34 of file bitefficient_format.cpp.

35 {
36  return char(0x20) + getBinDate(time);
37 }
static std::string getBinDate(const base::Time &time)
std::string fipa::acl::BitefficientFormat::getBinNumber ( uint32_t  number,
bool  asHex = false 
)
static

Retrieve number string

Definition at line 151 of file bitefficient_format.cpp.

152 {
153  std::string encoded;
154  if(asHex)
155  {
156  encoded += char(0x13);
157  } else {
158  encoded += char(0x12);
159  }
160 
161  std::stringstream ss;
162  ss << number;
163 
164  encoded += getDigits(ss.str());
165  return encoded;
166 }
static std::string getDigits(const std::string &numberString)
static std::string fipa::acl::BitefficientFormat::getBinStringNoCodetable ( const std::string &  sword)
inlinestatic

Definition at line 108 of file bitefficient_format.h.

108 { return char(0x14) + getNullTerminatedString(sword); }
static std::string getNullTerminatedString(const std::string &sword)
std::string fipa::acl::BitefficientFormat::getByteLengthEncodedString ( const std::string &  sword)
static

Definition at line 15 of file bitefficient_format.cpp.

16 {
17  char digitString[100];
18  int digit = sword.size();
19  snprintf(digitString,100, "#%d%c",digit,'\"');
20 
21  return digitString + sword;
22 }
std::string fipa::acl::BitefficientFormat::getCodedNaturalNumber ( const std::string &  cn)
static

Allow proper generation of natural numbers, will remove any leading zeros.

Definition at line 101 of file bitefficient_format.cpp.

102 {
103  std::string retstr;
104 
105  unsigned int i;
106  char code(0x00);
107  size_t decimal_size = cn.length();
108 
109  for(i = 0; i < decimal_size; ++i)
110  {
111  switch(cn[i])
112  {
113  // Ignoring leading zeros here,
114  case '0': code += char(0x01); break;
115  case '1': code += char(0x02); break;
116  case '2': code += char(0x03); break;
117  case '3': code += char(0x04); break;
118  case '4': code += char(0x05); break;
119  case '5': code += char(0x06); break;
120  case '6': code += char(0x07); break;
121  case '7': code += char(0x08); break;
122  case '8': code += char(0x09); break;
123  case '9': code += char(0x0a); break;
124  //case '+': code += char(0x0c); break;
125  //case 'e':
126  //case 'E': code += char(0x0d); break;
127  //case '-': code += char(0x0e); break;
128  //case '.': code += char(0x0f); break;
129  default:
130  assert(false);
131  }
132 
133 
134  if (i%2 == 0)
135  {
136  code = code<<4;
137  } else {
138  retstr += code;
139  code = char(0x00);
140  }
141  }
142 
143  if (i%2 != 0)
144  {
145  retstr += code;
146  }
147 
148  return retstr;
149 }
std::string fipa::acl::BitefficientFormat::getCodedNumber ( const std::string &  cn)
static

implements a coded number passed as a string it goes through it digit by digit(char by char)

Definition at line 67 of file bitefficient_format.cpp.

68 {
69  std::string retstr;
70  unsigned int i;
71  char code(0x00);
72  size_t decimal_size = cn.length();
73 
74  for(i = 0; i < decimal_size; i++)
75  {
76  if ((cn[i]>='0') && (cn[i]<='9')) code = char(code + 1 + int(cn[i]) - 48);
77  if (cn[i] == '+') code = char(code + 12);
78  if ((cn[i] == 'E') || (cn[i] == 'e')) code = char(code + 13);
79  if (cn[i] == '-') code = char(code + 14);
80  if (cn[i] == '.') code = char(code + 15);
81 
82  if (i%2 == 0)
83  {
84  code = code<<4;
85  } else {
86  retstr += code;
87  code = char(0x00);
88  }
89  }
90 
91  if (decimal_size % 2 != 0)
92  {
93  retstr += code;
94  } else {
95  retstr += char(0x00);
96  }
97 
98  return retstr;
99 }
static std::string fipa::acl::BitefficientFormat::getDigits ( const std::string &  numberString)
inlinestatic

Retrieve digits for a number string

Definition at line 83 of file bitefficient_format.h.

83 { return getCodedNumber(numberString); }
static std::string getCodedNumber(const std::string &cn)
implements a coded number passed as a string it goes through it digit by digit(char by char) ...
std::string fipa::acl::BitefficientFormat::getDigits ( uint32_t  number)
static

Get digits from unsigned integer

Definition at line 168 of file bitefficient_format.cpp.

169 {
170  std::stringstream ss;
171  ss << number;
172 
173  return getDigits(ss.str());
174 }
static std::string getDigits(const std::string &numberString)
static char fipa::acl::BitefficientFormat::getEOFCollection ( )
inlinestatic

returns the very used end-of-collection marker

Definition at line 19 of file bitefficient_format.h.

19 { return 0x01; }
static char fipa::acl::BitefficientFormat::getEOFEnvelope ( )
inlinestatic

Definition at line 21 of file bitefficient_format.h.

21 { return getEOFCollection(); }
static char getEOFCollection()
returns the very used end-of-collection marker
std::string fipa::acl::BitefficientFormat::getNullTerminatedString ( const std::string &  sword)
static

Definition at line 24 of file bitefficient_format.cpp.

25 {
26  return getByteLengthEncodedString(string) + char(0x00);
27 }
static std::string getByteLengthEncodedString(const std::string &sword)
std::string fipa::acl::BitefficientFormat::getReceivedObject ( const ReceivedObject object)
static

Retrieve encoded received object

Definition at line 194 of file bitefficient_format.cpp.

195 {
196  // by
197  std::string receivedObjectString = getNullTerminatedString(receivedObject.getBy());
198  // date
199  receivedObjectString += getBinDateTimeToken(receivedObject.getDate());
200  // from
201  std::string from = receivedObject.getFrom();
202  if(!from.empty())
203  {
204  receivedObjectString += char(0x02) + getNullTerminatedString(from);
205  }
206  // id
207  std::string id = receivedObject.getId();
208  if(!id.empty())
209  {
210  receivedObjectString += char(0x03) + getNullTerminatedString(id);
211  }
212  // via
213  std::string via = receivedObject.getVia();
214  if(!via.empty())
215  {
216  receivedObjectString += char(0x04) + getNullTerminatedString(via);
217  }
218 
219  const UserdefinedParameterList& list = receivedObject.getUserdefinedParameters();
220  std::vector<UserdefParam>::const_iterator cit = list.begin();
221  for(; cit != list.end(); ++cit)
222  {
223  receivedObjectString += char(0x00) + getNullTerminatedString(cit->getName()) + getNullTerminatedString(cit->getValue());
224  }
225 
226  receivedObjectString += getEOFCollection();
227 
228  return receivedObjectString;
229 }
static std::string getNullTerminatedString(const std::string &sword)
std::vector< UserdefParam > UserdefinedParameterList
Definition: userdef_param.h:94
static char getEOFCollection()
returns the very used end-of-collection marker
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...
std::string fipa::acl::BitefficientFormat::getString ( const std::string &  sword)
static

Return encoded string

Definition at line 9 of file bitefficient_format.cpp.

10 {
11  // StringLiteral | ByteLengthEncodedString
12  return getByteLengthEncodedString(sword);
13 }
static std::string getByteLengthEncodedString(const std::string &sword)

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