I got the answer. I am sharing the answer here so that anyone having this 
problem can use this. Thank you.

First solution is change the rpc call from 
rpc Hello(HelloRequest) returns (HelloResponse){}    to   rpc 
Hello(HelloRequest) returns (ServerInfo){}. This will work.

Second solution is when we have an obligation to not to change the rpc call 
then in server we can use the below code to call the ServerInfo fields and 
assign them to HelloResponse.

ServerInfo* serverinfo=new ServerInfo();
serverinfo->set_name("");
serverinfo->set_os("");
serverinfo->set_arch("");
serverinfo->set_nproc("");
HelloResponse* res;
res->set_allocated_server(serverinfo);



On Friday, October 29, 2021 at 8:43:20 AM UTC+5:30 Prasanna B wrote:

> Hello all,
> I am implementing a simple client-server grpc-c++ based application. In 
> the Hello rpc, I am taking the request and sending the fields of another 
> message called SeverInfo as response. The problem is I exactly don't know 
> how to send this ServerInfo data to a client from server side. We basically 
> use set_fieldname(ex: set_name) for general datatypes to send the data but 
> how should we send this serverInfo data to HelloResponse and then to 
> HelloRequest. Can somebody please help me??
>
>
> syntax = "proto3";
>
> package recognizer;
>
> service Recognizer {
>    rpc Hello(HelloRequest) returns (HelloResponse){}
> }
> message HelloRequest {
>     string name = 1;
> }
> message HelloResponse {
>     ServerInfo server = 1;
> }
> message ServerInfo {
>     string name = 1;
>     string os = 2;
>     string arch = 3;
>     int32 nproc = 4;
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/3aa2a6a6-82ed-4864-bcd5-f4c58cd5baf1n%40googlegroups.com.

Reply via email to