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::WriteReservation Class Reference
Loading...
Searching...
No Matches
pw::rpc2::WriteReservation Class Reference

Overview

A reserved buffer for writing an outbound RPC message in place.

Returned by ReserveWriteFuture (from Writer::ReserveWrite() or UnaryWriter::ReserveFinish()). Provides container-like access (data(), size(), operator[], iterators, and conversion to ByteSpan) to the reserved buffer.

Write the message into the buffer and call Commit() with the number of bytes written to send it. Destroying the reservation without calling Commit() (or calling Drop()) releases the buffer without sending anything.

Inheritance diagram for pw::rpc2::WriteReservation:
pw::rpc2::internal::WriteReservationBase

Public Member Functions

 WriteReservation (const WriteReservation &)=delete
 
WriteReservation & operator= (const WriteReservation &)=delete
 
 WriteReservation (WriteReservation &&) noexcept=default
 
WriteReservation & operator= (WriteReservation &&) noexcept=default
 
RpcStatus Commit (size_t size_bytes)
 
- Public Member Functions inherited from pw::rpc2::internal::WriteReservationBase
 WriteReservationBase (const WriteReservationBase &)=delete
 
WriteReservationBase & operator= (const WriteReservationBase &)=delete
 
 WriteReservationBase (WriteReservationBase &&other) noexcept=default
 
WriteReservationBase & operator= (WriteReservationBase &&other) noexcept
 
std::byte * data ()
 Returns a pointer to the start of the reserved write buffer.
 
const std::byte * data () const
 
size_t size () const
 Returns the size of the reserved write buffer in bytes.
 
std::byte & operator[] (size_t index)
 Accesses the byte at index.
 
const std::byte & operator[] (size_t index) const
 
iterator begin ()
 Returns an iterator to the beginning of the reserved buffer.
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 Returns an iterator to the end of the reserved buffer.
 
const_iterator end () const
 
const_iterator cend () const
 
void Drop ()
 Releases the reservation without sending any data.
 

Friends

class ReserveWriteFuture
 

Additional Inherited Members

- Public Types inherited from pw::rpc2::internal::WriteReservationBase
using iterator = ByteSpan::iterator
 
using const_iterator = ConstByteSpan::iterator
 
- Protected Member Functions inherited from pw::rpc2::internal::WriteReservationBase
 WriteReservationBase (transport::WriteReservation &&reservation, OutboundPacket packet, IntrusivePtr< Call > call)
 
RpcResult< IntrusivePtr< Call > > CommitAndTakeCall (size_t size_bytes)
 

Member Function Documentation

◆ Commit()

RpcStatus pw::rpc2::WriteReservation::Commit ( size_t  size_bytes)
inline

Sends the first size_bytes bytes of the reserved buffer.

Consumes the reservation; it cannot be used or committed again. size_bytes must not exceed size().

Returns
  • kOk: the message or response was queued for transmission.
  • kWriteClosed: this reservation was already committed, dropped, or moved from, or the call's outbound stream was already finished.
  • The call's completion status (such as kCancelled or kDisconnected) if the call ended with an error while the reservation was held. See Error handling.
  • kDisconnected: the connection closed before the write could be sent.

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