The QGrpcOperationContext class provides context for communication between an individual gRPC ™ operation and a channel. 更多...
| 头: |
#include <QGrpcOperationContext>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
|
| Since: | Qt 6.7 |
| 继承: | QObject |
| virtual | ~QGrpcOperationContext () override |
| QByteArrayView | argument () const |
| const QGrpcCallOptions & | callOptions () const & |
| QLatin1StringView | method () const |
| QMetaType | responseMetaType () const |
| std::shared_ptr<const QAbstractProtobufSerializer> | serializer () const |
(从 6.10 起)
const QMultiHash<QByteArray, QByteArray> &
|
serverInitialMetadata () const & |
(until 6.13)
const QHash<QByteArray, QByteArray> &
|
serverMetadata () const & |
(从 6.10 起)
const QMultiHash<QByteArray, QByteArray> &
|
serverTrailingMetadata () const & |
| QLatin1StringView | service () const |
| void | setResponseMetaType (QMetaType metaType ) |
(从 6.10 起)
void
|
setServerInitialMetadata (QMultiHash<QByteArray, QByteArray> && metadata ) |
(until 6.13)
void
|
setServerMetadata (QHash<QByteArray, QByteArray> && metadata ) |
(until 6.13)
void
|
setServerMetadata (const QHash<QByteArray, QByteArray> & metadata ) |
(从 6.10 起)
void
|
setServerTrailingMetadata (QMultiHash<QByteArray, QByteArray> && metadata ) |
| void | cancelRequested () |
| void | finished (const QGrpcStatus & status ) |
| void | messageReceived (const QByteArray & data ) |
| void | writeMessageRequested (const QByteArray & data ) |
| void | writesDoneRequested () |
QGrpcOperationContext is constructed internally when a remote procedure call (RPC) is requested, mediating interaction between the client's operation request and the channel's operation outcome.
RPCs requested on the client interface return specializations of QGrpcOperation ,譬如 QGrpcCallReply , QGrpcServerStream , QGrpcClientStream ,或 QGrpcBidiStream . These classes are implicitly integrated with the underlying QGrpcOperationContext counterpart.
注意: Don't use this class directly unless implementing a custom channel.
The signals contained within this class are used to build the communication between the client-facing QGrpcOperation 和 QAbstractGrpcChannel implementation. These operations are asynchronous in nature, and multiple RPCs can operate on the same channel concurrently. Channels typically treat all operations the same, and it is the channel's responsibility to correctly support and restrict the subset of features its RPC type supports.
Signals which should only be emitted by the channel's implementation are:
Signals which will be emitted by QGrpcOperation and its specializations are:
Custom implementations of QAbstractGrpcChannel must handle the client's signals, as no default signal handling is provided, and emit their own signals accordingly.
[until 6.13]
void
QGrpcOperationContext::
setServerMetadata
(
QHash
<
QByteArray
,
QByteArray
> &&
metadata
)
[until 6.13]
void
QGrpcOperationContext::
setServerMetadata
(const
QHash
<
QByteArray
,
QByteArray
> &
metadata
)
该函数计划在 6.13 版弃用。
使用 setServerInitialMetadata () 代替。
Sets the metadata received from the server at the start of the RPC.
另请参阅 setServerInitialMetadata ().
[override virtual noexcept]
QGrpcOperationContext::
~QGrpcOperationContext
()
Destroys the operation-context.
[noexcept]
QByteArrayView
QGrpcOperationContext::
argument
() const
Returns the serialized argument that is utilized by this operation-context.
[noexcept]
const
QGrpcCallOptions
&QGrpcOperationContext::
callOptions
() const &
Returns the call options that is utilized by this operation-context.
For channel-wide options, see QGrpcChannelOptions .
[signal]
void
QGrpcOperationContext::
cancelRequested
()
此信号发射由 QGrpcOperation when requesting cancellation of the communication.
The channel is expected to connect its cancellation logic to this signal and attempt to cancel the RPC and finish it with a Cancelled status code. Successful cancellation cannot be guaranteed. Further processing of the data received from a channel is not required and should be avoided.
另请参阅 QGrpcOperation::cancel .
[signal]
void
QGrpcOperationContext::
finished
(const
QGrpcStatus
&
status
)
This signal should be emitted by the channel when an RPC finishes.
It usually means that the server sent a status for the requested RPC and closed the connection. Implementations of QAbstractGrpcChannel should detect this situation and emit the signal.
After receiving this signal, no further communication should occur through this operation context. The client side may then safely delete the corresponding RPC object.
注意: This signal is implicitly connected to the QGrpcOperation counterpart.
另请参阅 QGrpcOperation::finished .
[signal]
void
QGrpcOperationContext::
messageReceived
(const
QByteArray
&
data
)
This signal should be emitted by the channel when a new chunk of data is received from the server.
For client streams and unary calls, this means that the single and final response has arrived and communication is about to finish.
For server and bidirectional streams, this signal should be continuously emitted by the channel upon receiving each new messages.
注意: This signal is implicitly connected to the QGrpcOperation counterpart.
另请参阅 QGrpcServerStream::messageReceived and QGrpcBidiStream::messageReceived .
[noexcept]
QLatin1StringView
QGrpcOperationContext::
method
() const
Returns the method name of the service associated with this operation-context.
Returns the meta type of the RPC result message.
另请参阅 setResponseMetaType ().
Returns the serializer of this operation-context
[noexcept, since 6.10]
const
QMultiHash
<
QByteArray
,
QByteArray
> &QGrpcOperationContext::
serverInitialMetadata
() const &
Returns the initial metadata received from the server before any response messages.
Initial metadata is sent by the server immediately after the call is established. It may include key-value pairs that provide context for the call.
注意:
QGrpcHttp2Channel
transports metadata as HTTP/2 headers.
键
are case-insensitive ASCII strings. You must avoid using the internal prefixes:
:
(pseudo-header),
grpc-
,或
qtgrpc-
.
值
may be either ASCII strings or binary data. For more information, see
RFC 7540, Section 8.1.2
.
注意: This method is used implicitly by QGrpcOperation .
该函数在 Qt 6.10 引入。
另请参阅 setServerInitialMetadata (), QGrpcOperation::serverInitialMetadata (),和 serverTrailingMetadata ().
[noexcept, until 6.13]
const
QHash
<
QByteArray
,
QByteArray
> &QGrpcOperationContext::
serverMetadata
() const &
该函数计划在 6.13 版弃用。
使用 serverInitialMetadata () 和 serverTrailingMetadata () 代替。
Returns the initial metadata received from the server before any response messages.
Initial metadata is sent by the server immediately after the call is established. It may include key-value pairs that provide context for the call.
注意:
QGrpcHttp2Channel
transports metadata as HTTP/2 headers.
键
are case-insensitive ASCII strings. You must avoid using the internal prefixes:
:
(pseudo-header),
grpc-
,或
qtgrpc-
.
值
may be either ASCII strings or binary data. For more information, see
RFC 7540, Section 8.1.2
.
注意: This method is used implicitly by QGrpcOperation .
另请参阅 setServerMetadata (), serverInitialMetadata (),和 QGrpcOperation::serverInitialMetadata ().
[noexcept, since 6.10]
const
QMultiHash
<
QByteArray
,
QByteArray
> &QGrpcOperationContext::
serverTrailingMetadata
() const &
Returns the trailing metadata received from the server after all response messages.
Trailing metadata is sent only by the server once all response messages have been sent and just before the RPC completes. It may include key-value pairs providing additional context about the completed call.
注意:
QGrpcHttp2Channel
transports metadata as HTTP/2 headers.
键
are case-insensitive ASCII strings. You must avoid using the internal prefixes:
:
(pseudo-header),
grpc-
,或
qtgrpc-
.
值
may be either ASCII strings or binary data. For more information, see
RFC 7540, Section 8.1.2
.
注意: This method is used implicitly by QGrpcOperation .
该函数在 Qt 6.10 引入。
另请参阅 QGrpcOperation::serverTrailingMetadata () 和 setServerTrailingMetadata ().
[noexcept]
QLatin1StringView
QGrpcOperationContext::
service
() const
Returns the service name associated with this operation-context.
Stores the metaType of the RPC result message.
另请参阅 responseMetaType ().
[since 6.10]
void
QGrpcOperationContext::
setServerInitialMetadata
(
QMultiHash
<
QByteArray
,
QByteArray
> &&
metadata
)
设置 metadata received from the server at the start of the RPC.
该函数在 Qt 6.10 引入。
另请参阅 serverInitialMetadata ().
[since 6.10]
void
QGrpcOperationContext::
setServerTrailingMetadata
(
QMultiHash
<
QByteArray
,
QByteArray
> &&
metadata
)
Sets the trailing metadata received from the server after all response messages.
该函数在 Qt 6.10 引入。
另请参阅 serverTrailingMetadata ().
[signal]
void
QGrpcOperationContext::
writeMessageRequested
(const
QByteArray
&
data
)
此信号发射由 QGrpcClientStream or QGrpcBidiStream when it has serialized data ready for a channel to deliver.
The channel is expected to connect its writing logic to this signal and wrap the serialized data in channel-related headers before writing it to the wire.
另请参阅 QGrpcClientStream::writeMessage and QGrpcBidiStream::writeMessage .
[signal]
void
QGrpcOperationContext::
writesDoneRequested
()
此信号发射由 QGrpcClientStream or QGrpcBidiStream to indicate that it's done writing messages. The channel should respond to this by half-closing the stream.
注意: After receiving this signal no more write operations are permitted for the streaming RPCs. The server can still send messages, which should be forwarded with messageReceived ().
另请参阅 QGrpcClientStream::writesDone and QGrpcBidiStream::writesDone .