25#ifndef GOBY_MIDDLEWARE_MARSHALLING_PROTOBUF_H
26#define GOBY_MIDDLEWARE_MARSHALLING_PROTOBUF_H
30#include <dccl/dynamic_protobuf_manager.h>
37#if GOOGLE_PROTOBUF_VERSION < 3001000
38#define ByteSizeLong ByteSize
46template <
typename DataType>
49 std::enable_if_t<!std::is_same<DataType, google::protobuf::Message>::value>>
54 std::vector<char> bytes(
msg.ByteSizeLong(), 0);
55 msg.SerializeToArray(bytes.data(), bytes.size());
66 static std::string
type_name(
const DataType& d = DataType())
68 return DataType::descriptor()->full_name();
72 template <
typename CharIterator>
73 static std::shared_ptr<DataType>
parse(CharIterator bytes_begin, CharIterator bytes_end,
74 CharIterator& actual_end,
77 auto msg = std::make_shared<DataType>();
78 msg->ParseFromArray(&*bytes_begin, bytes_end - bytes_begin);
79 actual_end = bytes_begin +
msg->ByteSizeLong();
90 std::vector<char> bytes(
msg.ByteSizeLong(), 0);
91 msg.SerializeToArray(bytes.data(), bytes.size());
106 static std::string
type_name(
const google::protobuf::Descriptor* desc)
108 return desc->full_name();
118 template <
typename CharIterator>
119 static std::shared_ptr<google::protobuf::Message>
120 parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator& actual_end,
121 const std::string& type,
bool user_pool_first =
false)
123 std::shared_ptr<google::protobuf::Message>
msg;
126 static std::mutex dynamic_protobuf_manager_mutex;
127 std::lock_guard<std::mutex> lock(dynamic_protobuf_manager_mutex);
130 dccl::DynamicProtobufManager::new_protobuf_message<google::protobuf::Message*>(
131 type, user_pool_first));
134 msg->ParseFromArray(&*bytes_begin, bytes_end - bytes_begin);
135 actual_end = bytes_begin +
msg->ByteSizeLong();
159 typename std::enable_if<std::is_enum<typename T::DCCLParameters>::value>::type* =
nullptr>
172template <
typename T,
typename std::enable_if<
173 std::is_base_of<google::protobuf::Message, T>::value>::type* =
nullptr>
176 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.