DCCL v4
dccl::DynamicProtobufManager Class Reference

Helper class for creating google::protobuf::Message objects that are not statically compiled into the application. More...

#include <dccl/dynamic_protobuf_manager.h>

Public Member Functions

 DynamicProtobufManager (const DynamicProtobufManager &)=delete
 
DynamicProtobufManageroperator= (const DynamicProtobufManager &)=delete
 

Static Public Member Functions

static const google::protobuf::Descriptor * find_descriptor (const std::string &protobuf_type_name, bool user_pool_first=false)
 Finds the Google Protobuf Descriptor (essentially a meta-class for a given Message) from a given Message name. More...
 
template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer new_protobuf_message (const std::string &protobuf_type_name, bool user_pool_first=false)
 Create a new (empty) Google Protobuf message of a given type by name. More...
 
template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer new_protobuf_message (const google::protobuf::Descriptor *desc)
 Create a new (empty) Google Protobuf message of a given type by Descriptor. More...
 
static std::shared_ptr< google::protobuf::Messagenew_protobuf_message (const google::protobuf::Descriptor *desc)
 Create a new (empty) Google Protobuf message of a given type by Descriptor. More...
 
static std::shared_ptr< google::protobuf::Messagenew_protobuf_message (const std::string &protobuf_type_name)
 Create a new (empty) Google Protobuf message of a given type by name. More...
 
static void add_database (std::shared_ptr< google::protobuf::DescriptorDatabase > database)
 Add a Google Protobuf DescriptorDatabase to the set of databases searched for Message Descriptors.
 
static void enable_compilation ()
 Enable on the fly compilation of .proto files on the local disk. Must be called before load_from_proto_file() is called.
 
static const google::protobuf::FileDescriptor * load_from_proto_file (const std::string &protofile_absolute_path)
 Load a message from a .proto file on the disk. enable_compilation() must be called first. More...
 
static void add_include_path (const std::string &path)
 Add a path for searching for import messages when loading .proto files using load_from_proto_file() More...
 
static void * load_from_shared_lib (const std::string &shared_lib_path)
 Load compiled .proto files from a UNIX shared library (i.e. *.so or *.dylib) More...
 
static void protobuf_shutdown ()
 
static const google::protobuf::FileDescriptor * add_protobuf_file (const google::protobuf::FileDescriptorProto &proto)
 Add a protobuf file defined in a google::protobuf::FileDescriptorProto.
 
static void reset ()
 
static void custom_deleter (DynamicProtobufManager *obj)
 
static google::protobuf::DynamicMessageFactory & msg_factory ()
 
static google::protobuf::DescriptorPool & user_descriptor_pool ()
 
static google::protobuf::SimpleDescriptorDatabase & simple_database ()
 
template<typename ReturnType , typename... Args1, typename... Args2>
static ReturnType msg_factory_call (ReturnType(google::protobuf::DynamicMessageFactory::*func)(Args1...) const, Args2... args)
 
template<typename ReturnType , typename... Args1, typename... Args2>
static ReturnType user_descriptor_pool_call (ReturnType(google::protobuf::DescriptorPool::*func)(Args1...) const, Args2... args)
 
template<typename ReturnType , typename... Args1, typename... Args2>
static ReturnType simple_database_call (ReturnType(google::protobuf::SimpleDescriptorDatabase::*func)(Args1...) const, Args2... args)
 

Detailed Description

Helper class for creating google::protobuf::Message objects that are not statically compiled into the application.

Definition at line 47 of file dynamic_protobuf_manager.h.

Member Function Documentation

◆ add_include_path()

void dccl::DynamicProtobufManager::add_include_path ( const std::string &  path)
static

Add a path for searching for import messages when loading .proto files using load_from_proto_file()

Exceptions
ExceptionIf enable_compilation() has not been called before using this function.

Definition at line 87 of file dynamic_protobuf_manager.cpp.

◆ find_descriptor()

const google::protobuf::Descriptor * dccl::DynamicProtobufManager::find_descriptor ( const std::string &  protobuf_type_name,
bool  user_pool_first = false 
)
static

Finds the Google Protobuf Descriptor (essentially a meta-class for a given Message) from a given Message name.

Parameters
protobuf_type_nameThe fully qualified name of the Google Protobuf Message including package name. E.g. in the .proto file:
package dccl.protobuf
message A { }
would result in protobuf_type_name == "dccl.protobuf.A"
user_pool_firstSearch the user pool first, then the generated (compiled-in) pool (useful in case the generated pool is missing extensions that are in the user pool)
Returns
A pointer to the google::protobuf::Descriptor (or nullptr if not found)

Definition at line 37 of file dynamic_protobuf_manager.cpp.

◆ load_from_proto_file()

const google::protobuf::FileDescriptor * dccl::DynamicProtobufManager::load_from_proto_file ( const std::string &  protofile_absolute_path)
static

Load a message from a .proto file on the disk. enable_compilation() must be called first.

Parameters
protofile_absolute_pathIt is critical that the argument be the absolute, canonical path to the file. (No relative paths and no "." or "..") This could be achieved, e.g., by using Boost filesystem as follows...
boost::filesystem::path abs_path = boost::filesystem::complete(rel_path);
abs_path.normalize();
Exceptions
ExceptionIf enable_compilation() has not been called before using this function
ExceptionIf any error exists in locating or parsing this .proto file.

It is critical that the argument be the absolute, canonical path to the file. This could be achieved, e.g., by using Boost filesystem as follows... boost::filesystem::path abs_path = boost::filesystem::complete(rel_path); abs_path.normalize();

Definition at line 113 of file dynamic_protobuf_manager.cpp.

◆ load_from_shared_lib()

void * dccl::DynamicProtobufManager::load_from_shared_lib ( const std::string &  shared_lib_path)
static

Load compiled .proto files from a UNIX shared library (i.e. *.so or *.dylib)

Parameters
shared_lib_pathPath to shared library. May be relative if known by ld.so

Definition at line 98 of file dynamic_protobuf_manager.cpp.

◆ new_protobuf_message() [1/4]

template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer dccl::DynamicProtobufManager::new_protobuf_message ( const google::protobuf::Descriptor *  desc)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by Descriptor.

Parameters
descThe Google Protobuf Descriptor of the message to create.
Template Parameters
GoogleProtobufMessagePointerA pointer or anything that acts like a pointer (has operator*()) to a google::protobuf::Message
Returns
A pointer to the newly created object. Deleting the memory is up to the caller of this function, so smart pointers (e.g. std::shared_ptr<google::protobuf::Message>) are recommended.

Definition at line 99 of file dynamic_protobuf_manager.h.

◆ new_protobuf_message() [2/4]

std::shared_ptr< google::protobuf::Message > dccl::DynamicProtobufManager::new_protobuf_message ( const google::protobuf::Descriptor *  desc)
static

Create a new (empty) Google Protobuf message of a given type by Descriptor.

Parameters
descThe Google Protobuf Descriptor of the message to create.
Returns
A std::shared_ptr to the newly created object.

Definition at line 66 of file dynamic_protobuf_manager.cpp.

◆ new_protobuf_message() [3/4]

std::shared_ptr< google::protobuf::Message > dccl::DynamicProtobufManager::new_protobuf_message ( const std::string &  protobuf_type_name)
static

Create a new (empty) Google Protobuf message of a given type by name.

Parameters
protobuf_type_nameThe full name (including package) of the Google Protobuf message to create (e.g. "package.MyMessage").
Returns
A std::shared_ptr to the newly created object.

Definition at line 73 of file dynamic_protobuf_manager.cpp.

◆ new_protobuf_message() [4/4]

template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer dccl::DynamicProtobufManager::new_protobuf_message ( const std::string &  protobuf_type_name,
bool  user_pool_first = false 
)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by name.

Parameters
protobuf_type_nameThe fully qualified name of the Google Protobuf Message including package name. E.g. in the .proto file:
package dccl.protobuf
message A { }
would result in protobuf_type_name == "dccl.protobuf.A"
Template Parameters
GoogleProtobufMessagePointerA pointer or anything that acts like a pointer (has operator*()) to a google::protobuf::Message
Returns
A pointer to the newly created object. Deleting the memory is up to the caller of this function, so smart pointers (e.g. std::shared_ptr<google::protobuf::Message>) are recommended.

Definition at line 77 of file dynamic_protobuf_manager.h.


The documentation for this class was generated from the following files: