Set seems to not set the field value

32 views
Skip to first unread message

Matteo Stefanini

unread,
May 10, 2023, 10:58:33 AM5/10/23
to grpc.io
Hi everyone,

I'm trying to send an integer back to the client but no data are sent.
The only solution found is to call 'response->counter()' before sending it

message Response
{
string message = 1;
uint32 time_ms = 2;
bool is_over = 3;
uint32 counter = 4;
}


Status Step(ServerContext* context, const service::Request* request, service::Response* response) override
{
response->set_message( "step_success" );
response->set_is_over( true );
response->set_counter( 10 );
response->counter();

return Status::OK;
}

Am I doing something wrong?

Tobias Krueger

unread,
May 10, 2023, 11:05:28 AM5/10/23
to grpc.io
>  Am I doing something wrong?

IMHO there must be something different.

The generated method "counter()" should be const (at least with new protoc compilers), therefor it cannot have any impact if you call it or not.

Matteo Stefanini

unread,
May 10, 2023, 11:59:36 AM5/10/23
to grpc.io

> The generated method "counter()" should be const (at least with new protoc compilers), therefor it cannot have any impact if you call it or not.

You are right, this is the implementation of the autogenerated code:

inline ::uint32_t Response::counter() const {
// @@protoc_insertion_point(field_get:Response.counter)
return _internal_counter();
}

Where can I check where the problem is?

I don't have a clue due to the very small part of the code being pretty straightforward

Tobias Krueger

unread,
May 11, 2023, 2:57:27 AM5/11/23
to grpc.io
Sorry - it is hard to tell what is wrong.
As a side effect (calling a const function) changes the behavior, you should search of some other generic problem (race-conditions, wrong/incompatible libraries, dangling pointers, whatever in C++ can go wrong).

Zach Reyes

unread,
May 17, 2023, 3:45:10 PM5/17/23
to grpc.io
Can you please post a longer code snippet (i.e. the full client and server side code snippet) so we can tell what's going on.
Reply all
Reply to author
Forward
0 new messages