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.
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 |
|
inline |
Serializes response, sends it, and completes the RPC with kOk. Not available on RawUnaryWriter; use FinishCopy() instead.
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.Finish().
|
inline |
Serializes response, sends it, and completes the RPC with kOk, moving response into the returned future. Not available on RawUnaryWriter; use FinishCopy() instead.
Finish().
|
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.
FinishCopy().
|
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.