Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw_rpc2
  5. Readers and writers
  6. pw::rpc2::UnaryWriter< Message > Class Template Reference
Loading...
Searching...
No Matches
pw::rpc2::UnaryWriter< Message > Class Template Reference

Overview

template<typename Message>
class pw::rpc2::UnaryWriter< Message >

Single-response writer for server unary and client-streaming RPCs.

Sends a single response and completes the RPC with kOk via FinishCopy() (raw bytes), Finish() (typed writers only), or ReserveFinish() (in-place write).

Destroying a UnaryWriter (or returning from the method's future or coroutine) before a response is committed ends the call with an error, which the client sees as kCancelled. If a Finish() future or ReserveFinish() reservation is still in flight when the UnaryWriter is destroyed, the call ends that way only if that future or reservation is dropped without committing.

Inheritance diagram for pw::rpc2::UnaryWriter< Message >:
pw::rpc2::internal::WriterBase

Public Member Functions

 UnaryWriter (const UnaryWriter &)=delete
 
UnaryWriter & operator= (const UnaryWriter &)=delete
 
 UnaryWriter (UnaryWriter &&) noexcept=default
 
UnaryWriter & operator= (UnaryWriter &&) noexcept=default
 
template<typename M = Message, typename = internal::EnableIfCopyableMessage<M>>
WriteFuture< Message > Finish (const Message &response)
 
template<typename M = Message, typename = std::enable_if_t<!std::is_same_v<M, ConstBuf>>>
WriteFuture< Message > Finish (Message &&response)
 
WriteFuture< ConstBuf > FinishCopy (ConstBuf &&response)
 
ReserveWriteFuture ReserveFinish (size_t max_message_size)
 
- Public Member Functions inherited from pw::rpc2::internal::WriterBase
 WriterBase (const WriterBase &)=delete
 
WriterBase & operator= (const WriterBase &)=delete
 
bool is_closed () const
 
void Cancel ()
 

Friends

struct internal::CallAccess
 

Additional Inherited Members

- Protected Types inherited from pw::rpc2::internal::WriterBase
enum  OnDestroy : bool { kFinishOnDestroy = false , kErrorOnDestroy = true }
 
- Protected Member Functions inherited from pw::rpc2::internal::WriterBase
 WriterBase (const IntrusivePtr< Call > &call, OnDestroy on_destroy)
 
 WriterBase (IntrusivePtr< Call > &&call, OnDestroy on_destroy)
 
 WriterBase (WriterBase &&) noexcept=default
 
WriterBase & operator= (WriterBase &&other) noexcept
 
size_t payload_limit () const
 
ReserveWriteFuture ReserveMessage (size_t max_message_size) const
 
ReserveWriteFuture ReserveStreamEnd () const
 
ReserveWriteFuture ReserveResponse (size_t max_message_size) const
 

Member Function Documentation

◆ Finish() [1/2]

template<typename Message >
template<typename M = Message, typename = internal::EnableIfCopyableMessage<M>>
WriteFuture< Message > pw::rpc2::UnaryWriter< Message >::Finish ( const Message &  response)
inline

Serializes response, sends it, and completes the RPC with kOk. Not available on RawUnaryWriter; use FinishCopy() instead.

Note
response is copied into the returned future. This overload is disabled for pw_protobuf messages with callback fields (since copying a message drops its callbacks); move them into Finish(Message&&) instead.
Warning
Committing the response retires the call and destroys the method's future or coroutine on the connection's next poll. Perform all per-call work before calling Finish().

◆ Finish() [2/2]

template<typename Message >
template<typename M = Message, typename = std::enable_if_t<!std::is_same_v<M, ConstBuf>>>
WriteFuture< Message > pw::rpc2::UnaryWriter< Message >::Finish ( Message &&  response)
inline

Serializes response, sends it, and completes the RPC with kOk, moving response into the returned future. Not available on RawUnaryWriter; use FinishCopy() instead.

Warning
Committing the response retires the call and destroys the method's future or coroutine on the connection's next poll. Perform all per-call work before calling Finish().

◆ FinishCopy()

template<typename Message >
WriteFuture< ConstBuf > pw::rpc2::UnaryWriter< Message >::FinishCopy ( ConstBuf &&  response)
inline

Copies response as the single response and completes the RPC with kOk.

Pass ConstBuf::Unowned(bytes) to copy from bytes that outlive the returned future, or move in an owned ConstBuf, which is released once copied.

Warning
Committing the response retires the call and destroys the method's future or coroutine on the connection's next poll. Perform all per-call work before calling FinishCopy().

◆ ReserveFinish()

template<typename Message >
ReserveWriteFuture pw::rpc2::UnaryWriter< Message >::ReserveFinish ( size_t  max_message_size)
inline

Reserves a buffer of at least max_message_size bytes for writing the response in place.

Committing the resulting WriteReservation sends the response and completes the RPC with kOk, retiring the call and destroying the method's future or coroutine. Dropping the reservation without committing reopens the UnaryWriter, or, if the UnaryWriter was already destroyed, ends the call as destroying it would have.


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