37 #include "console_bridge/console.h"
40 #include <boost/utility/string_ref.hpp>
44 #define SROS_SERIALIZE_PRIMITIVE(ptr, data) { memcpy(ptr, &data, sizeof(data)); ptr += sizeof(data); }
45 #define SROS_SERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(ptr, data, data_size); ptr += data_size; } }
46 #define SROS_DESERIALIZE_PRIMITIVE(ptr, data) { memcpy(&data, ptr, sizeof(data)); ptr += sizeof(data); }
47 #define SROS_DESERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(data, ptr, data_size); ptr += data_size; } }
51 #ifndef CONSOLE_BRIDGE_logError
52 # define CONSOLE_BRIDGE_logError(fmt, ...) \
53 console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__)
72 bool Header::parse(
const boost::shared_array<uint8_t>& buffer, uint32_t size, std::string& error_msg)
74 return parse(buffer.get(), size, error_msg);
77 bool Header::parse(uint8_t* buffer, uint32_t size, std::string& error_msg)
80 uint8_t* buf = buffer;
81 while (buf < buffer + size)
88 error_msg =
"Received an invalid TCPROS header. Each element must be prepended by a 4-byte length.";
94 boost::string_ref line((
char*)buf, len);
99 size_t eqpos = line.find_first_of(
"=");
100 if (eqpos == string::npos)
102 error_msg =
"Received an invalid TCPROS header. Each line must have an equals sign.";
107 boost::string_ref key_ref = line.substr(0, eqpos);
108 boost::string_ref value_ref = line.substr(eqpos+1);
110 key_.assign(key_ref.data(), key_ref.length());
112 (*read_map_)[key_].assign(value_ref.data(), value_ref.length());
120 M_string::const_iterator it =
read_map_->find(key);
136 M_string::const_iterator it = key_vals.begin();
137 M_string::const_iterator end = key_vals.end();
138 for (; it != end; ++it)
140 const std::string& key = it->first;
141 const std::string& value = it->second;
143 size += key.length();
144 size += value.length();
155 buffer.reset(
new uint8_t[size]);
156 char* ptr = (
char*)buffer.get();
160 M_string::const_iterator it = key_vals.begin();
161 M_string::const_iterator end = key_vals.end();
162 for (; it != end; ++it)
164 const std::string& key = it->first;
165 const std::string& value = it->second;
167 uint32_t len = key.length() + value.length() + 1;
170 static const char equals =
'=';
176 assert(ptr == (
char*)buffer.get() + size);