1 #pragma once
2 
3 #include <google/protobuf/message.h>
4 #include <google/protobuf/descriptor.h>
5 
6 // Utility functions for dealing with protos loaded from file rather than
7 //   compiled with protoc
8 namespace dynamicproto {
9 
10 using namespace google::protobuf;
11 
12 // init must be called before the other functions, telling the protobuf
13 //   factory where to look for imports.
14 void init(const std::vector<std::string>& include_dirs);
15 
16 // Return the file descriptor for file_name and all its imports. That for
17 // file_name is last in the vector.
18 std::vector<const FileDescriptor*> fileDescriptors(const std::string& file_name);
19 
20 // Find extensions of fully_qualified_name in desc and add them to exts
21 void extensionsOf(const FileDescriptor* desc,
22                   const std::string& fully_qualified_name,
23                   std::vector<const FieldDescriptor*>& exts);
24 
25 // Get all the enums in desc
26 std::vector<const EnumDescriptor*> enums(const FileDescriptor* desc);
27 
28 // Print the name and all possible values of e to o.
29 void print(const EnumDescriptor* e, std::ostream& o);
30 
31 // Create a new message defined in desc or one of its imports. message_type
32 //   is *not* qualified.
33 Message* newMessage(const FileDescriptor* desc, const std::string& message_type);
34 
35 } // namespace dynamicproto
36