@@ -60,18 +60,19 @@ CMessage::~CMessage()
6060 m_pConnectionInstance = nullptr ;
6161}
6262
63- void CMessage::setMessageObjects (std::shared_ptr<google::protobuf::Message> pMessageOwner, google::protobuf::Message* pMessage)
63+ void CMessage::setMessageObjects (std::shared_ptr<google::protobuf::Message> pMessageOwner, google::protobuf::Message* pMessage, const google::protobuf::Descriptor* pDescriptor )
6464{
6565 if (pMessageOwner.get () == nullptr )
6666 throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_INVALIDPARAM);
6767 if (pMessage == nullptr )
6868 throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_INVALIDPARAM);
69+ if (pDescriptor == nullptr )
70+ throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_INVALIDPARAM);
6971
7072 m_pMessageOwner = pMessageOwner;
7173 m_pMessage = pMessage;
7274
73- std::string sTypeName = m_pMessage->GetTypeName ();
74- m_pMessageDescriptor = m_pConnectionInstance->getMessageDescriptor (sTypeName );
75+ m_pMessageDescriptor = pDescriptor;
7576 m_pReflection = m_pMessage->GetReflection ();
7677
7778}
@@ -128,10 +129,17 @@ IMessage* CMessage::GetMessageField(const std::string& sFieldName)
128129 if (pFieldDescriptor == nullptr )
129130 throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND, " message field not found: " + sFieldName );
130131
132+ if (pFieldDescriptor->type () != google::protobuf::FieldDescriptor::Type::TYPE_MESSAGE)
133+ throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND, " field is not a message field: " + sFieldName );
134+
131135 google::protobuf::Message* pSubMessage = m_pReflection->MutableMessage (m_pMessage, pFieldDescriptor);
132136
133- std::unique_ptr<CMessage> pResult;
134- pResult->setMessageObjects (m_pMessageOwner, pSubMessage);
137+ if (pSubMessage == nullptr )
138+ throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND, " could not get mutable sub message: " + sFieldName );
139+
140+ std::unique_ptr<CMessage> pResult (new CMessage (m_pConnectionInstance));
141+
142+ pResult->setMessageObjects (m_pMessageOwner, pSubMessage, pFieldDescriptor->message_type ());
135143
136144 return pResult.release ();
137145}
0 commit comments