24 #ifndef GOBY_MIDDLEWARE_MARSHALLING_PROTOBUF_H
25 #define GOBY_MIDDLEWARE_MARSHALLING_PROTOBUF_H
29 #include <dccl/dynamic_protobuf_manager.h>
36 #if GOOGLE_PROTOBUF_VERSION < 3001000
37 #define ByteSizeLong ByteSize
45 template <
typename DataType>
53 std::vector<char> bytes(
msg.ByteSizeLong(), 0);
54 msg.SerializeToArray(bytes.data(), bytes.size());
65 static std::string
type_name(
const DataType& d = DataType())
67 return DataType::descriptor()->full_name();
71 template <
typename CharIterator>
72 static std::shared_ptr<DataType>
parse(CharIterator bytes_begin, CharIterator bytes_end,
73 CharIterator& actual_end,
76 auto msg = std::make_shared<DataType>();
77 msg->ParseFromArray(&*bytes_begin, bytes_end - bytes_begin);
78 actual_end = bytes_begin +
msg->ByteSizeLong();
89 std::vector<char> bytes(
msg.ByteSizeLong(), 0);
90 msg.SerializeToArray(bytes.data(), bytes.size());
105 static std::string
type_name(
const google::protobuf::Descriptor* desc)
107 return desc->full_name();
117 template <
typename CharIterator>
118 static std::shared_ptr<google::protobuf::Message>
119 parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator& actual_end,
120 const std::string&
type,
bool user_pool_first =
false)
122 std::shared_ptr<google::protobuf::Message>
msg;
125 static std::mutex dynamic_protobuf_manager_mutex;
126 std::lock_guard<std::mutex>
lock(dynamic_protobuf_manager_mutex);
127 msg = dccl::DynamicProtobufManager::new_protobuf_message<
128 std::shared_ptr<google::protobuf::Message>>(
type, user_pool_first);
131 msg->ParseFromArray(&*bytes_begin, bytes_end - bytes_begin);
132 actual_end = bytes_begin +
msg->ByteSizeLong();
155 template <
typename T,
156 typename std::enable_if<std::is_enum<typename T::DCCLParameters>::value>
::type* =
nullptr>
169 template <
typename T,
typename std::enable_if<
170 std::is_base_of<google::protobuf::Message, T>::value>
::type* =
nullptr>
173 return protobuf::detail::scheme_protobuf_or_dccl<T>(protobuf::detail::dccl_selector());