fipa_acl  1.4
serialized_letter.cpp
Go to the documentation of this file.
1 #include "serialized_letter.h"
2 #include <fipa_acl/message_parser/envelope_parser.h>
3 #include <fipa_acl/message_generator/envelope_generator.h>
4 #include <stdexcept>
5 
6 namespace fipa {
7 
9  : representation(fipa::acl::representation::UNKNOWN)
10  , timestamp(base::Time::now())
11 {
12 }
13 
14 
16  : representation(_representation)
17  , timestamp(base::Time::now())
18 {
19  std::string serializedLetter = fipa::acl::EnvelopeGenerator::create(letter, representation);
20  setData(serializedLetter);
21 }
22 
23 
25 {
27  fipa::acl::Letter letter;
28 
29  std::string serializedLetter = getDataAsString();
30  if( ep.parseData(serializedLetter, letter, representation) )
31  {
32  return letter;
33  }
34 
35  throw std::runtime_error("SerializedLetter: could not deserialize data correctly");
36 }
37 
38 void SerializedLetter::setData(const std::string& msg)
39 {
40  for(unsigned int i=0; i<msg.size(); i++)
41  {
42  this->data.push_back(msg[i]);
43  }
44 }
45 
47 {
48  std::string str = "";
49  for (std::vector<uint8_t>::const_iterator it = data.begin(); it != data.end(); it++)
50  str += (*it);
51  return str;
52 }
53 
54 } // end namespace fipa
static std::string create(const ACLEnvelope &msg, const representation::Type &acl_representation)
ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields...
Definition: acl_envelope.h:349
fipa::acl::Letter deserialize() const
static bool parseData(const std::string &storage, ACLEnvelope &envelope, representation::Type type=fipa::acl::representation::BITEFFICIENT)
fipa::acl::representation::Type representation
std::vector< uint8_t > data
void setData(const std::string &msg)
Foundation of Physical Intelligent Agents.
Definition: conversation.cpp:6
std::string getDataAsString() const