mirror of https://github.com/qt/qtgrpc.git
Extend interface of gRPC operation with methods supporting QProtobufMessage
Add the following methods: - QGrpcOperation::read(QProtobufMessage *message) const - QGrpcClientStream::sendMessage(const QProtobufMessage *message) - QGrpcBidirStream::sendMessage(const QProtobufMessage *message) Methods allow serializing/deserializing protobuf message using the interface base class. These methods use the serializeRawMessage and deserializeRawMessage methods of QAbstractProtobufSerializer, so in current implentation they work relatively slower than their template counterparts. [ChangeLog][GRPC] Added the following interfaces to gRPC operation classes: - QGrpcOperation::read(QProtobufMessage *message) const - QGrpcClientStream::sendMessage(const QProtobufMessage *message) - QGrpcBidirStream::sendMessage(const QProtobufMessage *message) Task-number: QTBUG-120972 Change-Id: I6fb1ec20efd680cb45ccf13833cd5b712d2dd0aa Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
This commit is contained in:
parent
e17d28e0d0
commit
2d0897ce66
|
|
@ -109,6 +109,29 @@ QByteArray QGrpcOperation::data() const
|
|||
return d_func()->data;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 6.8
|
||||
Reads a message from a raw byte array stored in QGrpcOperation.
|
||||
|
||||
The function writes a deserialized value to \a message pointer.
|
||||
|
||||
If deserialization is not successful the \l QGrpcOperation::errorOccurred
|
||||
signal is emitted.
|
||||
|
||||
\note This function has slower message deserialization compared to its
|
||||
template counterpart.
|
||||
|
||||
*/
|
||||
void QGrpcOperation::read(QProtobufMessage *message) const
|
||||
{
|
||||
Q_ASSERT_X(message != nullptr, "QGrpcOperation::read",
|
||||
"Can't read to nullptr QProtobufMessage");
|
||||
if (auto ser = serializer(); ser) {
|
||||
if (!ser->deserializeRawMessage(message, data()))
|
||||
emit errorOccurred(deserializationError());
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Getter of the metadata received from the channel. For the HTTP2 channels it
|
||||
usually contains the HTTP headers received from the server.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ public:
|
|||
return value;
|
||||
}
|
||||
|
||||
void read(QProtobufMessage *message) const;
|
||||
|
||||
QGrpcMetadata metadata() const;
|
||||
QLatin1StringView method() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,18 @@ QGrpcClientStream::QGrpcClientStream(std::shared_ptr<QGrpcChannelOperation> chan
|
|||
*/
|
||||
QGrpcClientStream::~QGrpcClientStream() = default;
|
||||
|
||||
/*!
|
||||
\since 6.8
|
||||
Serializes \a message and sends it to the server.
|
||||
|
||||
\note This function has slower message serialization compared to its
|
||||
template counterpart.
|
||||
*/
|
||||
void QGrpcClientStream::sendMessage(const QProtobufMessage *message)
|
||||
{
|
||||
sendMessage(serializer()->serializeRawMessage(message));
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Sends the serialized \a data to the server.
|
||||
|
|
@ -106,6 +118,18 @@ QGrpcBidirStream::QGrpcBidirStream(std::shared_ptr<QGrpcChannelOperation> channe
|
|||
*/
|
||||
QGrpcBidirStream::~QGrpcBidirStream() = default;
|
||||
|
||||
/*!
|
||||
\since 6.8
|
||||
Serializes \a message and sends it to the server.
|
||||
|
||||
\note This function has slower message serialization compared to its
|
||||
template counterpart.
|
||||
*/
|
||||
void QGrpcBidirStream::sendMessage(const QProtobufMessage *message)
|
||||
{
|
||||
sendMessage(serializer()->serializeRawMessage(message));
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Sends the serialized \a data to the server.
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ public:
|
|||
sendMessage(serializer()->serialize<T>(&message));
|
||||
}
|
||||
|
||||
void sendMessage(const QProtobufMessage *message);
|
||||
|
||||
private:
|
||||
void sendMessage(const QByteArray &data);
|
||||
};
|
||||
|
|
@ -59,6 +61,8 @@ public:
|
|||
sendMessage(serializer()->serialize<T>(&message));
|
||||
}
|
||||
|
||||
void sendMessage(const QProtobufMessage *message);
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue