userver: ugrpc::FieldsVisitor Class Reference
Loading...
Searching...
No Matches
ugrpc::FieldsVisitor Class Referencefinal

#include <userver/ugrpc/protobuf_visit.hpp>

Detailed Description

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.

Warning
You should not construct this at runtime as it performs significant computations in the constructor to precompile the visitors. You should create this ones at start-up.

Example usage:

Definition at line 190 of file protobuf_visit.hpp.

+ Inheritance diagram for ugrpc::FieldsVisitor:

Public Types

using Selector
 
enum  LockBehavior
 

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 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 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.
 
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.
 

Member Typedef Documentation

◆ Selector

using ugrpc::FieldsVisitor::Selector
Initial value:
utils::function_ref<
bool(const google::protobuf::Descriptor& descriptor, const google::protobuf::FieldDescriptor& field)>

Definition at line 192 of file protobuf_visit.hpp.

Member Enumeration Documentation

◆ LockBehavior

enum ugrpc::BaseVisitor::LockBehavior
stronginherited

Definition at line 68 of file protobuf_visit.hpp.

Constructor & Destructor Documentation

◆ FieldsVisitor() [1/2]

ugrpc::FieldsVisitor::FieldsVisitor ( Selector selector,
LockBehavior lock_behavior )

Creates the visitor with custom thread locking behavior and the given selector for runtime compilation.

Warning
Do not use this unless you know what you are doing.

◆ FieldsVisitor() [2/2]

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.

Warning
Do not use this unless you know what you are doing.

Member Function Documentation

◆ CompileGenerated() [1/2]

void ugrpc::BaseVisitor< FieldVisitCallback >::CompileGenerated ( std::string_view message_name)
inlineinherited

Compiles the visitor for the given generated message type and its dependent types.

Definition at line 90 of file protobuf_visit.hpp.

◆ CompileGenerated() [2/2]

void ugrpc::BaseVisitor< FieldVisitCallback >::CompileGenerated ( utils::span< std::string_view > message_names)
inlineinherited

Compiles the visitor for the given generated message type and their dependent types.

Definition at line 94 of file protobuf_visit.hpp.

◆ Visit()

void ugrpc::BaseVisitor< FieldVisitCallback >::Visit ( google::protobuf::Message & message,
FieldVisitCallback callback )
inherited

Execute a callback without recursion.

Equivalent to VisitFields but utilizes the precompilation data from Compile

◆ VisitRecursive()

void ugrpc::BaseVisitor< FieldVisitCallback >::VisitRecursive ( google::protobuf::Message & message,
FieldVisitCallback callback )
inherited

Execute a callback recursively.

Equivalent to VisitFieldsRecursive and VisitMessagesRecursive but utilizes the precompilation data from Compile


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