Skip to content

Commit 5589582

Browse files
Implemented Sub Fields
1 parent 2c7c0d9 commit 5589582

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

Implementation/libgrpcwrapper_connectinstance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ CConnectionInstance::CConnectionInstance(const std::string& sProtobufDefinition,
112112

113113
CConnectionInstance::~CConnectionInstance()
114114
{
115+
m_pMessageFactory = nullptr;
116+
m_pFileDescriptor = nullptr;
115117
m_pImporter = nullptr;
116118
m_pErrorCollector = nullptr;
117119
m_pSourceTree = nullptr;
120+
m_pChannel = nullptr;
118121
}
119122

120123

Implementation/libgrpcwrapper_message.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Implementation/libgrpcwrapper_message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CMessage : public virtual IMessage, public virtual CBase {
6969

7070
protected:
7171

72-
void setMessageObjects (std::shared_ptr<google::protobuf::Message> pMessageOwner, google::protobuf::Message * pMessage);
72+
void setMessageObjects (std::shared_ptr<google::protobuf::Message> pMessageOwner, google::protobuf::Message * pMessage, const google::protobuf::Descriptor * pDescriptor);
7373

7474
public:
7575

Implementation/libgrpcwrapper_request.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ CRequest::CRequest(std::shared_ptr<CConnectionInstance> pConnectionInstance, con
6060
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_INVALIDRESPONSETYPEIDENTIFIER, "invalid response type identifier: " + sResponseTypeIdentifier);
6161

6262
auto pOwner = pConnectionInstance->createMessage(sRequestTypeIdentifier);
63-
setMessageObjects(pOwner, pOwner.get());
63+
auto pDescriptor = pConnectionInstance->getMessageDescriptor(sRequestTypeIdentifier);
64+
65+
setMessageObjects(pOwner, pOwner.get(), pDescriptor);
6466

6567
}
6668

Implementation/libgrpcwrapper_response.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ CResponse::CResponse(std::shared_ptr<CConnectionInstance> pConnectionInstance, c
7070
if (!pMessage->ParseFromString(serializedResponse))
7171
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_FAILEDTOPARSEREQUESTRESPONSE, "empty request response: " + m_sResponseTypeIdentifier);
7272

73-
setMessageObjects(pMessage, pMessage.get());
73+
auto pDescriptor = pConnectionInstance->getMessageDescriptor(sResponseTypeIdentifier);
74+
75+
setMessageObjects(pMessage, pMessage.get(), pDescriptor);
7476
}
7577

7678
CResponse::~CResponse()

0 commit comments

Comments
 (0)