Hi everybody,
Has anybody been using the v3 Any objects in C++ and had success?
Everything I am trying with them is completely failing and I'm wondering if
there is something that I'm missing or doing wrong.
In my case I know that my Any object will correspond to a specific type so
I first tried unpacking into an instance of that type. No success.
Next I tried using the Is() method to see if the UnpackTo() was failing due
to something internal to that method. The Is() method is also returning
false for the type that I'm providing.
To get some information about what type the Any really thought it was, I
used the type_url() method. This returned a string that, as far as I can
tell, corresponds to the type that I am trying to unpack into (for
reference, the specific string I was getting back is
"type.googleapis.com/com.here.pb.hdmap.platform.v1.core.LinkParametricAttributionList").
Next I got the full_name from the descriptor of the message that I was
trying to unpack into to see if maybe something wasn't matching up. I got
back the exact same string as was returned by type_url() except without the
leading "type.googleapis.com/" (for reference it was
"com.here.pb.hdmap.platform.v1.core.LinkParametricAttributionList").
As a last-ditch attempt to figure out what was going on (and to check if
the problem was in fact a string mismatch), I created a new Any object from
the original, used set_type_url() to set the type_url to exactly the same
thing as the full_name that I got back from the descriptor, and *still* my
call to the Is() method (using the new Any object) returned false.
Sometimes code speaks louder than words so here is an example of code that
I think should be working but isn't:
const ::google::protobuf::Any& anyMessage = <get from a protobuf
message>
const std::string anyUrl = anyMessage.type_url();
::com::here::pb::hdmap::platform::v1::core::LinkParametricAttributionList
coreLinkParametricAttributionList;
const std::string aName =
coreLinkParametricAttributionList.GetDescriptor()->full_name();
if
(anyMessage.Is<::com::here::pb::hdmap::platform::v1::core::LinkParametricAttributionList>())
{
// Never gets into here.
}
So now I'm thoroughly baffled. In summary, when I ask the message for a
string telling me type it is, it tells me that it is of a certain type.
But if I use the Is() method with that type, it returns false. Even if I
set the type_url() string to exactly match what I get from the descriptor
of the type that I'm trying to unpack into it still says it's not that type.
Does anybody have any thoughts on what could be going wrong here?
-Justin
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.