#include <userver/ugrpc/protobuf_visit.hpp>
Collects knowledge of the structure of the protobuf messages allowing for efficient loops over fields to apply a callback to the ones selected by the 'selector' function.
If you do not have static knowledge of the required fields, you should use VisitFields or VisitFieldsRecursive that are equivalent to FieldsVisitor with a return true;
selector.
Example usage:
Definition at line 243 of file protobuf_visit.hpp.
Public Types | |
using | Selector = utils::function_ref<bool(const google::protobuf::FieldDescriptor& field)> |
enum class | LockBehavior { kNone = 0 , kShared = 1 } |
Public Member Functions | |
FieldsVisitor (Selector selector) | |
Creates the visitor with the given selector and compiles it for the message types we can find. | |
FieldsVisitor (Selector selector, const DescriptorList &descriptors) | |
Creates the visitor with the given selector and compiles it for the given message types and their fields recursively. | |
FieldsVisitor (Selector selector, LockBehavior lock_behavior) | |
Creates the visitor with custom thread locking behavior and the given selector for runtime compilation. | |
FieldsVisitor (Selector selector, const DescriptorList &descriptors, LockBehavior lock_behavior) | |
Creates the visitor with custom thread locking behavior and the given selector; compiles it for the given message types. | |
void | Visit (google::protobuf::Message &message, FieldVisitCallback callback) |
Execute a callback without recursion. | |
void | VisitRecursive (google::protobuf::Message &message, FieldVisitCallback callback) |
Execute a callback recursively. | |
void | Compile (const google::protobuf::Descriptor *descriptor) |
Compiles the visitor for the given message type and its dependent types. | |
void | Compile (const DescriptorList &descriptors) |
Compiles the visitor for the given message types and their dependent types. | |
void | CompileAllGenerated () |
Compiles the visitor for all message types we can find. Not guaranteed to find all message types. | |
void | CompileGenerated (std::string_view message_name) |
Compiles the visitor for the given generated message type and its dependent types. | |
void | CompileGenerated (utils::span< std::string_view > message_names) |
Compiles the visitor for the given generated message type and their dependent types. | |
bool | ContainsSelected (const google::protobuf::Descriptor *descriptor) |
Efficiently checks if the message contains any selected structures. | |
using ugrpc::FieldsVisitor::Selector = utils::function_ref<bool(const google::protobuf::FieldDescriptor& field)> |
Definition at line 245 of file protobuf_visit.hpp.
|
stronginherited |
Enumerator | |
---|---|
kNone | Do not take shared_mutex locks for any operation on the visitor. |
kShared | Take shared_lock for all read operations on the visitor and unique_lock for all Compile operations. |
Definition at line 72 of file protobuf_visit.hpp.
ugrpc::FieldsVisitor::FieldsVisitor | ( | Selector | selector, |
LockBehavior | lock_behavior ) |
Creates the visitor with custom thread locking behavior and the given selector for runtime compilation.
ugrpc::FieldsVisitor::FieldsVisitor | ( | Selector | selector, |
const DescriptorList & | descriptors, | ||
LockBehavior | lock_behavior ) |
Creates the visitor with custom thread locking behavior and the given selector; compiles it for the given message types.
|
inherited |
Efficiently checks if the message contains any selected structures.
You may want to call this before Visit and VisitRecursive to avoid a copy of the message beforehand if you require one.
|
inlineinherited |
Execute a callback without recursion.
Equivalent to VisitFields but utilizes the precompilation data from Compile
Definition at line 178 of file protobuf_visit.hpp.
|
inlineinherited |
Execute a callback recursively.
Equivalent to VisitFieldsRecursive and VisitMessagesRecursive but utilizes the precompilation data from Compile
Definition at line 190 of file protobuf_visit.hpp.