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
45template <
typename DataType>
48 std::enable_if_t<!std::is_same<DataType, google::protobuf::Message>::value>>
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();
156 typename std::enable_if<std::is_enum<typename T::DCCLParameters>::value>::type* =
nullptr>
169template <
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());
const Descriptor * GetDescriptor() const
detail namespace with internal helper functions
constexpr int scheme_protobuf_or_dccl(dccl_selector)
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Enumeration and helper functions for marshalling scheme identification.
static std::shared_ptr< DataType > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
Parse Protobuf message (using standard Protobuf decoding)
static std::vector< char > serialize(const DataType &msg)
Serialize Protobuf message (standard Protobuf encoding)
static std::string type_name(const DataType &d=DataType())
Full protobuf Message name, including package (if one is defined).
static std::string type_name(const google::protobuf::Descriptor *desc)
Full protobuf name from descriptor, including package (if one is defined).
static std::vector< char > serialize(const google::protobuf::Message &msg)
Serialize Protobuf message (standard Protobuf encoding)
static std::shared_ptr< google::protobuf::Message > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type, bool user_pool_first=false)
Parse Protobuf message (using standard Protobuf decoding) given the Protobuf type name and assuming t...
static std::string type_name(const google::protobuf::Message &d)
Full protobuf name from message instantiation, including package (if one is defined).
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
static std::string type_name()
The marshalling scheme specific string name for this type.