26 #ifndef LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED 27 #define LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED 35 #include <google/protobuf/any.pb.h> 36 #include <google/protobuf/message.h> 37 #include <google/protobuf/reflection.h> 38 #include <google/protobuf/repeated_field.h> 43 #include <type_traits> 44 #include <unordered_set> 72 bool has_oneof(google::protobuf::Message
const& msg,
73 std::string
const& oneof_name);
80 google::protobuf::Message
const&
82 std::string
const& oneof_name);
88 std::string
which_oneof(google::protobuf::Message
const& msg,
89 std::string
const& oneof_name);
92 std::string
message_type(google::protobuf::Message
const& msg);
95 std::string
message_type(google::protobuf::Any
const& any);
102 template <
typename T>
103 auto as_vector(google::protobuf::Message
const& msg,
104 std::string
const& field_name) -> std::vector<T>;
110 template <
typename T>
111 auto as_vector(google::protobuf::RepeatedField<T>
const&) -> std::vector<T>;
117 template <
typename T>
118 auto as_vector(google::protobuf::RepeatedPtrField<T>
const&) -> std::vector<T>;
127 template <
typename OutT,
typename InT>
128 auto to_vector(google::protobuf::RepeatedField<InT>
const& rf)
129 -> std::vector<OutT>;
132 template <
typename T>
133 auto as_set(google::protobuf::Message
const& msg, std::string
const& field_name)
140 template <
typename T>
141 auto as_set(google::protobuf::RepeatedField<T>
const&) -> std::set<T>;
147 auto as_set(google::protobuf::RepeatedPtrField<std::string>
const&)
148 -> std::set<std::string>;
154 template <
typename OutT,
typename InT>
155 auto to_set(google::protobuf::RepeatedField<InT>
const&) -> std::set<OutT>;
158 template <
typename T>
160 std::string
const& field_name) -> std::unordered_set<T>;
166 template <
typename T>
168 -> std::unordered_set<T>;
174 auto as_unordered_set(google::protobuf::RepeatedPtrField<std::string>
const&)
175 -> std::unordered_set<std::string>;
181 template <
typename OutT,
typename InT>
183 -> std::unordered_set<OutT>;
190 void fill(std::istream& is, google::protobuf::Message& msg);
193 void fill(std::string
const& pbuf_str, google::protobuf::Message& msg);
196 void load(std::string
const& pbuf_filename, google::protobuf::Message& msg);
199 void serialize(std::ostream& os, google::protobuf::Message
const& msg);
202 std::string
serialize(google::protobuf::Message
const& msg);
205 void serialize(std::string
const& pbuf_filename,
206 google::protobuf::Message
const& msg);
213 template <
typename T,
typename ContainerT>
215 ContainerT
const& values);
219 template <
typename ContainerT>
229 void fill(std::istream& is, google::protobuf::Message& msg);
232 void fill(std::string
const& str, google::protobuf::Message& msg);
235 void load(std::string
const& ptext_filename, google::protobuf::Message& msg);
238 void write(std::ostream& os, google::protobuf::Message
const& msg);
241 std::string
write(google::protobuf::Message
const& msg);
244 void write(std::string
const& ptext_filename,
245 google::protobuf::Message
const& msg);
251 #endif // LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from a binary stream.
google::protobuf::uint8 uint8
void write(std::ostream &os, google::protobuf::Message const &msg)
Write the protobuf message in prototext in a stream.
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
google::protobuf::int32 int32
auto as_unordered_set(google::protobuf::Message const &msg, std::string const &field_name) -> std::unordered_set< T >
Extract the values from the named field as an unordered_set.
void load(std::string const &pbuf_filename, google::protobuf::Message &msg)
Fill the protobuf message from a binary file.
auto to_vector(google::protobuf::RepeatedField< InT > const &rf) -> std::vector< OutT >
Convert the repeated field to an STL vector of given type.
void load(std::string const &ptext_filename, google::protobuf::Message &msg)
Fill the protobuf message from prototext in a file.
google::protobuf::uint16 uint16
std::string to_space_sep_string(ContainerT const &values)
Concatenate a container of strings into a single string. Elements are space separated.
auto to_set(google::protobuf::RepeatedField< InT > const &) -> std::set< OutT >
Convert the repeated field to an STL set of given type.
void assign_to_repeated(google::protobuf::RepeatedField< T > &field, ContainerT const &values)
Assign a range of values to a repeated protobuf field.
google::protobuf::int64 int64
void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from prototext in a stream.
google::protobuf::uint32 uint32
auto as_set(google::protobuf::Message const &msg, std::string const &field_name) -> std::set< T >
Extract the values from the named field as a set.
google::protobuf::uint64 uint64
google::protobuf::int16 int16
bool has_oneof(google::protobuf::Message const &msg, std::string const &oneof_name)
Test whether the message has a oneof field with the given name.
google::protobuf::int8 int8
auto to_unordered_set(google::protobuf::RepeatedField< InT > const &) -> std::unordered_set< OutT >
Convert the repeated field to an STL unordered_set of given type.
google::protobuf::Message const & get_oneof_message(google::protobuf::Message const &msg, std::string const &oneof_name)
Get a message in a oneof from the given message.
std::string which_oneof(google::protobuf::Message const &msg, std::string const &oneof_name)
Get the name of the set field in the named oneof.
std::string message_type(google::protobuf::Message const &msg)
Get the name of the message type as a string.
auto as_vector(google::protobuf::Message const &msg, std::string const &field_name) -> std::vector< T >
Extract the values from the named field as a vector.