I’m trying to create a Backend Service usable by other cpp classes in my project.
I want the service to already deserialize the incoming data and parse it into a struct.
I’m currently not getting this work generically:
Header File:
// SendMessageStruct works correctly
template<typename InStructType>
void SendMessageStruct(const FString& destination, const InStructType& InStruct)
{
SendMessageStruct(destination, InStructType::StaticStruct(), &InStruct);
}
void SendMessageStruct(const FString& destination, const UStruct* StructDefinition, const void* Struct);
// SubscribeStruct does not compile.
template<typename OutStructType>
void SubscribeStruct(const FString& Destination, TBaseDynamicDelegate<FWeakObjectPtr, void, OutStructType> Delegate)
{
const auto Callback = FStompSubscriptionEvent::CreateLambda([Delegate](const IStompMessage& Message)
{
OutStructType ResponseData;
FJsonObjectConverter::JsonObjectStringToUStruct<OutStructType>(Message.GetBodyAsString(), &ResponseData, 0, 0, 0);
Delegate.ExecuteIfBound(ResponseData);
});
Subscribe(Destination, Callback);
}
void Subscribe(const FString& Destination, const FStompSubscriptionEvent& Callback);
I’m calling it in the following way, with FNpcServerManagedData
being a USTRUCT.
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnNpcServerManagedDataUpdate, FNpcServerManagedData, Data);
...
BackendCommunication->SubscribeStruct("/topic/npc/" + NpcId + "/flushManagedData", OnNpcServerManagedDataUpdate);
But when I’m trying to compile I get the following error:
0>C:\Projekte\Dukes of Frisia\Game\DukesOfFrisia\Source\Communication\Public\BackendCommunication.h(37): Error C2039 : "ExecuteIfBound" ist kein Member von "TBaseDynamicDelegate<FWeakObjectPtr,void,FNpcServerManagedData>".
0>C:\Projekte\Dukes of Frisia\Game\DukesOfFrisia\Source\Communication\Public\NpcCommunication.h(28): Reference : Siehe Deklaration von "TBaseDynamicDelegate<FWeakObjectPtr,void,FNpcServerManagedData>"
0>C:\Projekte\Dukes of Frisia\Game\DukesOfFrisia\Source\Communication\Private\NpcCommunication.cpp(50): Reference : Siehe Verweis auf die gerade kompilierte Instanziierung "void UBackendCommunication::SubscribeStruct<FNpcServerManagedData>(const FString &,TBaseDynamicDelegate<FWeakObjectPtr,void,FNpcServerManagedData>)" der Funktions-Vorlage.
0>C:\Projekte\Dukes of Frisia\Game\DukesOfFrisia\Source\Communication\Public\BackendCommunication.h(37): Error C2039 : "__this" ist kein Member von "TBaseDynamicDelegate<FWeakObjectPtr,void,FNpcServerManagedData>".
0>C:\Projekte\Dukes of Frisia\Game\DukesOfFrisia\Source\Communication\Public\NpcCommunication.h(28): Reference : Siehe Deklaration von "TBaseDynamicDelegate<FWeakObjectPtr,void,FNpcServerManagedData>"
What am I doing wrong? Is it not possible to call ExecuteIfBound on a generic type?