Is there a C++ Any.pack() equivalent?

30 views
Skip to first unread message

Eric Hansen

unread,
Oct 19, 2020, 4:01:08 PM10/19/20
to grpc.io

In my C++ grpc server, I'm trying to pack another proto (e.t. deviceStatus) into the Status proto but I cannot find 'Any' in the c++ API, nor any examples about how to do this in C++

This is how I do it in Java...

com.google.rpc.Status build = com.google.rpc.Status.newBuilder() .setCode(grpcErrorCode.getNumber()) .setMessage(dex.getMessage()) .addDetails(Any.pack(deviceStatus)) .build();

Thanks for any pointers...

Russell Wu

unread,
Oct 20, 2020, 5:24:38 AM10/20/20
to Eric Hansen, grpc.io
In C++, `error_details` in grpc::Status is a string. So you probably want to serialize your object to the wire format or json. If there's a Any field in a message, you should be able to do something like this:

```
MyMessage msg;
Any any = msg.mutable_someanyfield();
any->PackFrom(myobject);
```

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/11a263cf-69da-44d5-b8f2-7f0e3f7fc79an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages