userver: ugrpc::MessagesVisitor Class Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
ugrpc::MessagesVisitor Class Referencefinal

Your opinion will help to improve our service

Leave a feedback >

#include <userver/ugrpc/protobuf_visit.hpp>

Detailed Description

Collects knowledge of the structure of the protobuf messages allowing for efficient loops over nested messages to apply a callback to the ones selected by the 'selector' function.

If you do not have static knowledge of the required messages, you should use VisitMessagesRecursive that is equivalent to MessagesVisitor 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.

Definition at line 297 of file protobuf_visit.hpp.

+ Inheritance diagram for ugrpc::MessagesVisitor:

Public Types

using Selector = utils::function_ref<bool(const google::protobuf::Descriptor& descriptor)>
 
enum  LockBehavior
 

Public Member Functions

 MessagesVisitor (Selector selector)
 Creates the visitor with the given selector for runtime compilation and compiles it for the message types we can find.
 
 MessagesVisitor (Selector selector, const DescriptorList &descriptors)
 Creates the visitor with the given selector and compiles it for the given message types and their fields recursively.
 
 MessagesVisitor (Selector selector, LockBehavior lock_behavior)
 Creates the visitor with custom thread locking behavior and the given selector for runtime compilation.
 
 MessagesVisitor (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, MessageVisitCallback callback)
 Execute a callback without recursion.
 
void VisitRecursive (google::protobuf::Message &message, MessageVisitCallback 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.
 

Member Typedef Documentation

◆ Selector

using ugrpc::MessagesVisitor::Selector = utils::function_ref<bool(const google::protobuf::Descriptor& descriptor)>

Definition at line 299 of file protobuf_visit.hpp.

Member Enumeration Documentation

◆ LockBehavior

Definition at line 72 of file protobuf_visit.hpp.

Constructor & Destructor Documentation

◆ MessagesVisitor() [1/2]

ugrpc::MessagesVisitor::MessagesVisitor ( 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.

◆ MessagesVisitor() [2/2]

ugrpc::MessagesVisitor::MessagesVisitor ( 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

◆ ContainsSelected()

bool ugrpc::VisitorCompiler::ContainsSelected ( const google::protobuf::Descriptor * descriptor)
inherited

Efficiently checks if the message contains any selected structures.

You may want to call this before BaseVisitor::Visit and BaseVisitor::VisitRecursive to avoid a copy of the message beforehand if you require one.

◆ Visit()

void ugrpc::BaseVisitor< MessageVisitCallback >::Visit ( google::protobuf::Message & message,
MessageVisitCallback callback )
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.

◆ VisitRecursive()

void ugrpc::BaseVisitor< MessageVisitCallback >::VisitRecursive ( google::protobuf::Message & message,
MessageVisitCallback callback )
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.


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