On Thu, Jan 7, 2016 at 6:11 PM, Justin Link <[email protected]>
wrote:

> Everything that I've been trying has been failing completely so I'm
> wondering if there is something that I missing or doing wrong.
>
> To summarize, I have an Any message (let's call it mA) that I know
> contains a certain other specific message (call it messageTypeB).  If I
> create an instance of messageTypeB (call it mB) and mA.UnpackTo(&mB) it
> fails.  If I use the mA.Is<messageTypeB>() method it also returns false.
> If I compare mA.type_url() to mB.GetDescriptor()->full_name() they differ
> only in that the former has "type.googleapis.com/" at the front.  So it
> seems that they do/should be corresponding to the same type.  Yet the Is()
> method still says they don't.
>
> Just to see what would happen I tried creating a new Any object (call it
> mANew) from mA and use set_type_url() to set the url to exactly the string
> that I'm getting back from mB, but even then mANew.Is<messageTypeB>()
> returns false.
>
>
> Sometimes code speaks louder than words so here is an example of what I'm
> doing that seems like it should work but isn't:
>
>         const ::vthree::protobuf::Any& anyMessage =
> parametricAttribution.layer_specific_attribution();
>         const std::string anyUrl =
> anyMessage.type_url();
> // anyUrl is "
> type.googleapis.com/com.here.pb.hdmap.platform.v1.core.LinkParametricAttributionList
> "
>
>
> ::com::here::pb::hdmap::platform::v1::core::LinkParametricAttributionList
> coreLinkParametricAttributionList;
>         const std::string aName =
> coreLinkParametricAttributionList.GetDescriptor()->full_name();
> // aName is
> "com.here.pb.hdmap.platform.v1.core.LinkParametricAttributionList"
>
>         if
> (anyMessage.Is<::com::here::pb::hdmap::platform::v1::core::LinkParametricAttributionList>())
>         {
>                 // It never gets in here.
>         }
>
>
> So now I'm thoroughly baffled (and going a little crazy).  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.
>
> Has anybody else been using Any objects in C++ and had success?  If so,
> were you doing anything different than what I've shown here?  Elsewhere at
> my company we are using these same protobuf binary files in Java and having
> no problems
> so either I'm missing something here or the problem might be specific to
> the C++ libraries.   (For reference we're using Beta-1 but it didn't seem
> like Beta-2 offered any changes that would be related.)
>
How did you create the Any message? Can you try the following:
SomeMessageType foo = ...;
google::protobuf::Any any_message;
any_message.PackFrom(foo);
if (any_message.Is<SomeMessageType>()) {
  // It should get 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.
>

-- 
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.

Reply via email to