userver: ugrpc::server::CallContextBase Class Reference
Loading...
Searching...
No Matches
ugrpc::server::CallContextBase Class Reference

Detailed Description

Definition at line 27 of file call_context.hpp.

Inheritance diagram for ugrpc::server::CallContextBase:

Public Member Functions

 CallContextBase (CallContextBase &&)=delete
CallContextBase & operator= (CallContextBase &&)=delete
grpc::ServerContextBase & GetServerContext ()
const grpc::ServerContextBase & GetServerContext () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string_view GetCallName () const
 Name of the RPC in the format full.path.ServiceName/MethodName.
std::string_view GetServiceName () const
 Get name of gRPC service.
std::string_view GetMethodName () const
 Get name of called gRPC method.
tracing::Span & GetSpan ()
 Get the span of the current RPC.
utils::OptionalRef< google::protobuf::Arena > GetArena () const
 Borrow the call's protobuf arena.
std::shared_ptr< google::protobuf::Arena > GetArenaSharedPtr () const noexcept
 Share ownership of the call's protobuf arena.
utils::AnyStorage< StorageContext > & GetStorageContext ()
 Returns call context for storing per-call custom data.

Member Function Documentation

◆ GetArena()

utils::OptionalRef< google::protobuf::Arena > ugrpc::server::CallContextBase::GetArena ( ) const

Borrow the call's protobuf arena.

Returns
An empty reference if arenas are disabled or the call is generic. To retain arena messages beyond the call's lifetime, keep a shared pointer obtained with ugrpc::server::CallContextBase::GetArenaSharedPtr.

◆ GetArenaSharedPtr()

std::shared_ptr< google::protobuf::Arena > ugrpc::server::CallContextBase::GetArenaSharedPtr ( ) const
noexcept

Share ownership of the call's protobuf arena.

Returns
An empty pointer if arenas are disabled or the call is generic. The call retains ownership; the returned pointer can extend the lifetime of the arena and its messages beyond the call's lifetime.

◆ GetServerContext()

grpc::ServerContextBase & ugrpc::server::CallContextBase::GetServerContext ( )

◆ GetStorageContext()

utils::AnyStorage< StorageContext > & ugrpc::server::CallContextBase::GetStorageContext ( )

Returns call context for storing per-call custom data.

The context can be used to pass data from server middleware to client handler or from one middleware to another one.

Example usage:

In authentication middleware:

if (password_is_correct) {
// Username is authenticated, set it in per-call storage context
context.GetStorageContext().Emplace(kAuthUsername, username);
}

In client handler:

const auto& username = context.GetStorageContext().Get(kAuthUsername);
auto msg = fmt::format("Hello, {}!", username);

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