userver: ugrpc Namespace Reference
Loading...
Searching...
No Matches
ugrpc Namespace Reference

Detailed Description

Asynchronous gRPC driver.

Namespaces

namespace  client
 Client-side utilities.
 
namespace  server
 Server-side utilities.
 
namespace  tests
 userver gRPC testing facilities
 

Classes

class  BaseVisitor
 Base class for FieldsVisitor and MessagesVisitor. Provides the interface and contains common code to use the data collected in the VisitorCompiler. More...
 
class  FieldMask
 Utilities to process the field masks. Respects Google's AIP-161: https://google.aip.dev/161. More...
 
class  FieldsVisitor
 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. More...
 
class  MessagesVisitor
 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. More...
 
class  VisitorCompiler
 Base class for BaseVisitor. Constructs and manages the descriptor graph to collect the data about the messages and enable the visitors to find all selected structures. More...
 

Typedefs

using MessageVisitCallback = utils::function_ref<void(google::protobuf::Message&)>
 
using FieldVisitCallback
 
using DescriptorList = std::vector<const google::protobuf::Descriptor*>
 
using FieldDescriptorList = std::vector<const google::protobuf::FieldDescriptor*>
 

Functions

grpc::ByteBuffer SerializeToByteBuffer (const ::google::protobuf::Message &message, std::size_t block_size=kDefaultSerializeBlockSize)
 Serialize a Protobuf message to the wire format.
 
bool ParseFromByteBuffer (grpc::ByteBuffer &&buffer, ::google::protobuf::Message &message)
 Parse a Protobuf message from the wire format.
 
formats::json::Value MessageToJson (const google::protobuf::Message &message)
 Returns formats::json::Value representation of protobuf message.
 
std::string ToString (const google::protobuf::Message &message)
 Converts message to human readable string.
 
std::string ToJsonString (const google::protobuf::Message &message)
 Returns Json-string representation of protobuf message.
 
void VisitFields (google::protobuf::Message &message, FieldVisitCallback callback)
 Execute a callback for all non-empty fields of the message.
 
void VisitMessagesRecursive (google::protobuf::Message &message, MessageVisitCallback callback)
 Execute a callback for the message and its non-empty submessages.
 
void VisitFieldsRecursive (google::protobuf::Message &message, FieldVisitCallback callback)
 Execute a callback for all fields of the message and its non-empty submessages.
 
void VisitNestedMessage (google::protobuf::Message &message, const google::protobuf::FieldDescriptor &field, MessageVisitCallback callback)
 Execute a callback for the submessage contained in the given field.
 
FieldDescriptorList GetFieldDescriptors (const google::protobuf::Descriptor &descriptor)
 Get the descriptors of fields in the message.
 
DescriptorList GetNestedMessageDescriptors (const google::protobuf::Descriptor &descriptor)
 Get the descriptors of current and nested messages.
 
const google::protobuf::Descriptor * FindGeneratedMessage (std::string_view name)
 Find a generated type by name.
 
const google::protobuf::FieldDescriptor * FindField (const google::protobuf::Descriptor *descriptor, std::string_view field)
 Find the field of a generated type by name.
 
grpc::StatusCode StatusCodeFromString (std::string_view str)
 Convert string to grpc::StatusCode.
 
std::string_view ToString (grpc::StatusCode code) noexcept
 Convert grpc::StatusCode to string.
 
bool IsServerError (grpc::StatusCode code) noexcept
 Whether a given status code is definitely a server-side error.
 

Variables

constexpr std::size_t kDefaultSerializeBlockSize = 4096
 

Typedef Documentation

◆ DescriptorList

using ugrpc::DescriptorList = std::vector<const google::protobuf::Descriptor*>

Definition at line 50 of file protobuf_visit.hpp.

◆ FieldDescriptorList

using ugrpc::FieldDescriptorList = std::vector<const google::protobuf::FieldDescriptor*>

Definition at line 52 of file protobuf_visit.hpp.

◆ FieldVisitCallback

using ugrpc::FieldVisitCallback
Initial value:
utils::function_ref<void(google::protobuf::Message&, const google::protobuf::FieldDescriptor&)>

Definition at line 31 of file protobuf_visit.hpp.

◆ MessageVisitCallback

using ugrpc::MessageVisitCallback = utils::function_ref<void(google::protobuf::Message&)>

Definition at line 29 of file protobuf_visit.hpp.

Function Documentation

◆ IsServerError()

bool ugrpc::IsServerError ( grpc::StatusCode code)
noexcept

Whether a given status code is definitely a server-side error.

Currently includes:

  • UNKNOWN
  • UNIMPLEMENTED
  • INTERNAL
  • UNAVAILABLE
  • DATA_LOSS

We intentionally do not include CANCELLED and DEADLINE_EXPIRED here, because the situation may either be considered not erroneous at all (when a client explicitly cancels an RPC; when a client attempts an RPC with a very short deadline), or there is no single obvious service to blame (when the collective deadline expires for an RPC tree).

◆ MessageToJson()

formats::json::Value ugrpc::MessageToJson ( const google::protobuf::Message & message)

Returns formats::json::Value representation of protobuf message.

Exceptions
SerializationError

◆ ParseFromByteBuffer()

bool ugrpc::ParseFromByteBuffer ( grpc::ByteBuffer && buffer,
::google::protobuf::Message & message )

Parse a Protobuf message from the wire format.

Parameters
bufferthe buffer that might be tempered with during deserialization
messagewill contain the parsing result on success
Returns
true on success, false if buffer does not contain a valid message, according to the derived type of message

◆ SerializeToByteBuffer()

grpc::ByteBuffer ugrpc::SerializeToByteBuffer ( const ::google::protobuf::Message & message,
std::size_t block_size = kDefaultSerializeBlockSize )

Serialize a Protobuf message to the wire format.

Parameters
messagethe message to serialize
block_sizecan be used for performance tuning, too small chunk size results in extra allocations, too large chunk size results in wasting memory
Exceptions
std::runtime_erroron serialization errors (supposedly only happens on extremely rare allocation failures or proto reflection malfunctioning).

◆ StatusCodeFromString()

grpc::StatusCode ugrpc::StatusCodeFromString ( std::string_view str)

Convert string to grpc::StatusCode.

Exceptions
std::runtime_error

◆ ToJsonString()

std::string ugrpc::ToJsonString ( const google::protobuf::Message & message)

Returns Json-string representation of protobuf message.

Exceptions
formats::json::Exception

Variable Documentation

◆ kDefaultSerializeBlockSize

constexpr std::size_t ugrpc::kDefaultSerializeBlockSize = 4096
inlineconstexpr
See also
SerializeToByteBuffer

Definition at line 16 of file byte_buffer_utils.hpp.