diff --git a/src/grpc/qgrpcoperation.cpp b/src/grpc/qgrpcoperation.cpp index eb465f02..388f4550 100644 --- a/src/grpc/qgrpcoperation.cpp +++ b/src/grpc/qgrpcoperation.cpp @@ -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. diff --git a/src/grpc/qgrpcoperation.h b/src/grpc/qgrpcoperation.h index b4c1e940..371f43ba 100644 --- a/src/grpc/qgrpcoperation.h +++ b/src/grpc/qgrpcoperation.h @@ -31,6 +31,8 @@ public: return value; } + void read(QProtobufMessage *message) const; + QGrpcMetadata metadata() const; QLatin1StringView method() const; diff --git a/src/grpc/qgrpcstream.cpp b/src/grpc/qgrpcstream.cpp index 78dca81a..2ad05784 100644 --- a/src/grpc/qgrpcstream.cpp +++ b/src/grpc/qgrpcstream.cpp @@ -64,6 +64,18 @@ QGrpcClientStream::QGrpcClientStream(std::shared_ptr 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 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. diff --git a/src/grpc/qgrpcstream.h b/src/grpc/qgrpcstream.h index b53dc4a3..0f997f70 100644 --- a/src/grpc/qgrpcstream.h +++ b/src/grpc/qgrpcstream.h @@ -41,6 +41,8 @@ public: sendMessage(serializer()->serialize(&message)); } + void sendMessage(const QProtobufMessage *message); + private: void sendMessage(const QByteArray &data); }; @@ -59,6 +61,8 @@ public: sendMessage(serializer()->serialize(&message)); } + void sendMessage(const QProtobufMessage *message); + Q_SIGNALS: void messageReceived();