On 19/11/2021 04:57, Daggumati, Rajesh wrote:
typedef boost::tuple<std::string, BinaryBuffer_t> DecodeErrorPayload_t; RegisterIONotification(NotifyType type;,boost::any payload)
[...]
void RegisterIOThreaded::OnDecodeError( const std::string& error, BinaryBuffer_t data ) { RegisterIONotification notify(RegisterIONotification::TypeDecodeError ,make_tuple(error, data)); [...] ASSERT_NO_THROW(payload = boost::any_cast<RegisterIONotification::DecodeErrorPayload_t>(notify.Payload));// Here its got failed...Please help me to fix this.
You have to be *very* careful about using type inference and implicit casts when using boost::any. For example, it's entirely possible that make_tuple is returning a type that is compatible with DecodeErrorPayload_t but is not actually DecodeErrorPayload_t, which will cause your later any_cast to fail. (Especially if you're calling std::make_tuple rather than boost::make_tuple, which seems likely.) You can inspect the payload in a debugger to determine what type it actually is (although it can be hard to interpret). Or, (while undocumented) it does contain a type() method that you can call and log to inspect the actual type. You may get better results if you explicitly static_cast your make_tuple call to the type that you're expecting, or use uniform construction syntax instead of make_tuple.