31 #include <boost/shared_ptr.hpp>
33 #include <rsc/runtime/TypeStringTools.h>
36 #include "rsb/rsbexports.h"
47 template<
typename ProtocolBuffer>
58 deserialize(
const std::string& wireType,
const std::string& wire);
65 if (type_name.size() >= 6 && type_name.substr(0, 6) ==
"class ") {
69 std::string result =
".";
71 for (std::string::const_iterator it
72 = type_name.begin() + (skip ? 6 : 0);
73 it != type_name.end(); ++it) {
79 result.push_back(
'.');
83 result.push_back(*it);
97 template<
typename ProtocolBuffer>
99 Converter<std::string> (rsc::runtime::typeName<ProtocolBuffer>(),
100 typeNameToWireSchema(rsc::runtime::typeName<
101 ProtocolBuffer>())) {
104 template<
typename ProtocolBuffer>
108 template<
typename ProtocolBuffer>
111 assert(data.first == getDataType());
113 boost::shared_ptr<ProtocolBuffer> s = boost::static_pointer_cast<
114 ProtocolBuffer>(data.second);
115 s->SerializeToString(&wireData);
116 return getWireSchema();
119 template<
typename ProtocolBuffer>
121 const std::string& wireSchema,
const std::string& wireData) {
122 assert(wireSchema == getWireSchema());
124 boost::shared_ptr<ProtocolBuffer> result(
new ProtocolBuffer());
125 result->ParseFromString(wireData);
126 return std::make_pair(getDataType(), result);
std::pair< std::string, boost::shared_ptr< void > > AnnotatedData
A combination of data type and the actual data.
std::string typeNameToProtoName(const std::string &type_name)
virtual ~ProtocolBufferConverter()
A generic converter for data types based on Protocol Buffer messages.
std::string typeNameToWireSchema(const std::string &type_name)
AnnotatedData deserialize(const std::string &wireType, const std::string &wire)
Deserializes a domain object from a wire type.
std::string serialize(const AnnotatedData &data, std::string &wire)
Serialized the given domain object to the wire.
ProtocolBufferConverter()