Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt gRPC - support for nested stream messages
Forum Updated to NodeBB v4.3 + New Features

Qt gRPC - support for nested stream messages

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 764 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blackqsav
    wrote on last edited by
    #1

    Hello,

    I want to use Qt gRPC which was provided in Qt 6.5. However, I'm facing some problems when I try to use nested messages.

    My proto file looks as follows:

    package TestPackage;
    
    service Tester {
      rpc Test (Empty) returns (stream TestReply) {}
    }
    
    message TestReply{
        TestReplyData data = 1;
        int32 id = 2;
    }
    
    message TestReplyData {
        string testData1 = 1;
        int32 testData2 = 2;
    }
    
    message Empty {
    
    }
    

    On the server side ("raw" C++ gRPC) I have following implementation:

        Status Test(::grpc::ServerContext* context,
                    const ::TestPackage::Empty* request,
                    ::grpc::ServerWriter< ::TestPackage::TestReply>* writer) override
        {
            TestReply reply;
            TestPackage::TestReplyData* myData = new TestPackage::TestReplyData{};
            myData->set_testdata1("testdata1");
            myData->set_testdata2(1);
            reply.set_id(10);
            reply.set_allocated_data(myData); // or *reply.mutable_data() = ...;
    
            writer->Write(reply);
            return Status::OK;
        }
    

    On the client side (Qt gRPC) I have the following implementation:

    
        auto stream = m_client->streamTest(TestPackage::Empty());
    
        QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [this, stream]() {
            auto callback = stream->read<TestPackage::TestReply>();
    
            TestPackage::TestReplyData data = callback.data();
    
            qDebug() << "ID: " << callback.id_proto();
            qDebug() << "TestData1: " << data.testData1();
            qDebug() << "TestData2: " << data.testData2();
        });
    

    the output is:

    qt.protobuf: No deserializer for type TestPackage::TestReplyData*
    qt.grpc: "No deserializer was found for a given type."
    ID:  0
    TestData1:  ""
    TestData2:  0
    setCachingEnabled:  18  bytesDownloaded
    

    when there is an "id" field set only, without "set_allocated_data" on the server side (or mutable_data()) the data is sent correctly, so I assume that the problem is with setting nested messages.

    TestReply reply;
    TestPackage::TestReplyData* myData = new TestPackage::TestReplyData{};
    myData->set_testdata1("testdata1");
    myData->set_testdata2(1);
    reply.set_id(10);
    //*reply.mutable_data() = *myData;
    
    writer->Write(reply);
    return Status::OK;
    
    client's output is:
    
    ID:  10
    TestData1:  ""
    TestData2:  0
    setCachingEnabled:  7  bytesDownloaded
    

    Would that mean that this kind of proto file is not supported fully as for now?

    I also noticed that it seems that Qt gRPC does not support "oneof" in the messages, is that right?

    Christian EhrlicherC 1 Reply Last reply
    0
    • B Blackqsav

      Hello,

      I want to use Qt gRPC which was provided in Qt 6.5. However, I'm facing some problems when I try to use nested messages.

      My proto file looks as follows:

      package TestPackage;
      
      service Tester {
        rpc Test (Empty) returns (stream TestReply) {}
      }
      
      message TestReply{
          TestReplyData data = 1;
          int32 id = 2;
      }
      
      message TestReplyData {
          string testData1 = 1;
          int32 testData2 = 2;
      }
      
      message Empty {
      
      }
      

      On the server side ("raw" C++ gRPC) I have following implementation:

          Status Test(::grpc::ServerContext* context,
                      const ::TestPackage::Empty* request,
                      ::grpc::ServerWriter< ::TestPackage::TestReply>* writer) override
          {
              TestReply reply;
              TestPackage::TestReplyData* myData = new TestPackage::TestReplyData{};
              myData->set_testdata1("testdata1");
              myData->set_testdata2(1);
              reply.set_id(10);
              reply.set_allocated_data(myData); // or *reply.mutable_data() = ...;
      
              writer->Write(reply);
              return Status::OK;
          }
      

      On the client side (Qt gRPC) I have the following implementation:

      
          auto stream = m_client->streamTest(TestPackage::Empty());
      
          QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [this, stream]() {
              auto callback = stream->read<TestPackage::TestReply>();
      
              TestPackage::TestReplyData data = callback.data();
      
              qDebug() << "ID: " << callback.id_proto();
              qDebug() << "TestData1: " << data.testData1();
              qDebug() << "TestData2: " << data.testData2();
          });
      

      the output is:

      qt.protobuf: No deserializer for type TestPackage::TestReplyData*
      qt.grpc: "No deserializer was found for a given type."
      ID:  0
      TestData1:  ""
      TestData2:  0
      setCachingEnabled:  18  bytesDownloaded
      

      when there is an "id" field set only, without "set_allocated_data" on the server side (or mutable_data()) the data is sent correctly, so I assume that the problem is with setting nested messages.

      TestReply reply;
      TestPackage::TestReplyData* myData = new TestPackage::TestReplyData{};
      myData->set_testdata1("testdata1");
      myData->set_testdata2(1);
      reply.set_id(10);
      //*reply.mutable_data() = *myData;
      
      writer->Write(reply);
      return Status::OK;
      
      client's output is:
      
      ID:  10
      TestData1:  ""
      TestData2:  0
      setCachingEnabled:  7  bytesDownloaded
      

      Would that mean that this kind of proto file is not supported fully as for now?

      I also noticed that it seems that Qt gRPC does not support "oneof" in the messages, is that right?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Blackqsav said in Qt gRPC - support for nested stream messages:

      TestPackage::TestReply

      The documentation is not ready yet but I would guess you have to provide a (de)serialization function somehow. See https://doc.qt.io/qt-6/qtgrpc-index.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • M Offline
        M Offline
        martonmiklos
        wrote on last edited by
        #3

        @Blackqsav said in Qt gRPC - support for nested stream messages:

        qt.protobuf: No deserializer for type TestPackage::TestReplyData*

        You need to call qRegisterProtobufTypes() to eliminate this issue.

        T 1 Reply Last reply
        2
        • semlanikS Offline
          semlanikS Offline
          semlanik
          wrote on last edited by semlanik
          #4

          Hi @Blackqsav

          It could be an issue, but need some extra investigation, could you please confirm that the code generated using your scheme doesn't produce the same error with the minimal main:

          int main()
          {
          QProtobufSerializer ser;
          TestPackage::TestReplyData data;
          data.deserialize(&ser, QByteArray::fromHex("0a0474657374"));
          return 0;
          }

          1 Reply Last reply
          0
          • M martonmiklos

            @Blackqsav said in Qt gRPC - support for nested stream messages:

            qt.protobuf: No deserializer for type TestPackage::TestReplyData*

            You need to call qRegisterProtobufTypes() to eliminate this issue.

            T Offline
            T Offline
            talksik
            wrote on last edited by
            #5

            @martonmiklos Thanks for this!

            I can't believe this fixed it for me. Why in the world is this required when it's not mentioned in the docs at all. The protobuf and grpc modules are in technical preview, but I am surprised how careless Qt can be with this sort of thing. At least put it in the docs!

            semlanikS 1 Reply Last reply
            0
            • T talksik

              @martonmiklos Thanks for this!

              I can't believe this fixed it for me. Why in the world is this required when it's not mentioned in the docs at all. The protobuf and grpc modules are in technical preview, but I am surprised how careless Qt can be with this sort of thing. At least put it in the docs!

              semlanikS Offline
              semlanikS Offline
              semlanik
              wrote on last edited by semlanik
              #6

              @talksik it's an issue, but not the undocumented thing. The method should be called implicitly, but it wasn't.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved