本文整理汇总了C++中FUniqueNetIdRepl::NetSerialize方法的典型用法代码示例。如果您正苦于以下问题:C++ FUniqueNetIdRepl::NetSerialize方法的具体用法?C++ FUniqueNetIdRepl::NetSerialize怎么用?C++ FUniqueNetIdRepl::NetSerialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FUniqueNetIdRepl
的用法示例。
在下文中一共展示了FUniqueNetIdRepl::NetSerialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestUniqueIdRepl
void TestUniqueIdRepl(UWorld* InWorld)
{
#if !UE_BUILD_SHIPPING
bool bSuccess = true;
TSharedPtr<const FUniqueNetId> UserId = UOnlineEngineInterface::Get()->GetUniquePlayerId(InWorld, 0);
FUniqueNetIdRepl EmptyIdIn;
if (EmptyIdIn.IsValid())
{
UE_LOG(LogNet, Warning, TEXT("EmptyId is valid."), *EmptyIdIn->ToString());
bSuccess = false;
}
FUniqueNetIdRepl ValidIdIn(UserId);
if (!ValidIdIn.IsValid() || UserId != ValidIdIn.GetUniqueNetId() || *UserId != *ValidIdIn)
{
UE_LOG(LogNet, Warning, TEXT("UserId input %s != UserId output %s"), *UserId->ToString(), *ValidIdIn->ToString());
bSuccess = false;
}
if (bSuccess)
{
TArray<uint8> Buffer;
for (int32 i = 0; i < 2; i++)
{
Buffer.Empty();
FMemoryWriter TestWriteUniqueId(Buffer);
if (i == 0)
{
// Normal serialize
TestWriteUniqueId << EmptyIdIn;
TestWriteUniqueId << ValidIdIn;
}
else
{
// Net serialize
bool bOutSuccess = false;
EmptyIdIn.NetSerialize(TestWriteUniqueId, NULL, bOutSuccess);
ValidIdIn.NetSerialize(TestWriteUniqueId, NULL, bOutSuccess);
}
FMemoryReader TestReadUniqueId(Buffer);
FUniqueNetIdRepl EmptyIdOut;
TestReadUniqueId << EmptyIdOut;
if (EmptyIdOut.GetUniqueNetId().IsValid())
{
UE_LOG(LogNet, Warning, TEXT("EmptyId %s should have been invalid"), *EmptyIdOut->ToString());
bSuccess = false;
}
FUniqueNetIdRepl ValidIdOut;
TestReadUniqueId << ValidIdOut;
if (*UserId != *ValidIdOut.GetUniqueNetId())
{
UE_LOG(LogNet, Warning, TEXT("UserId input %s != UserId output %s"), *ValidIdIn->ToString(), *ValidIdOut->ToString());
bSuccess = false;
}
}
}
if (bSuccess)
{
FString OutString;
TSharedRef<FJsonValue> JsonValue = ValidIdIn.ToJson();
bSuccess = JsonValue->TryGetString(OutString);
if (bSuccess)
{
FUniqueNetIdRepl NewIdOut;
NewIdOut.FromJson(OutString);
bSuccess = NewIdOut.IsValid();
}
}
if (!bSuccess)
{
UE_LOG(LogNet, Warning, TEXT("TestUniqueIdRepl test failure!"));
}
#endif
}
示例2: TestUniqueIdRepl
void TestUniqueIdRepl(UWorld* InWorld)
{
bool bSuccess = true;
IOnlineIdentityPtr IdentityPtr = Online::GetIdentityInterface(InWorld);
if (IdentityPtr.IsValid())
{
TSharedPtr<FUniqueNetId> UserId = IdentityPtr->GetUniquePlayerId(0);
FUniqueNetIdRepl EmptyIdIn;
if (EmptyIdIn.IsValid())
{
UE_LOG(LogNet, Warning, TEXT("EmptyId is valid."), *EmptyIdIn->ToString());
bSuccess = false;
}
FUniqueNetIdRepl ValidIdIn(UserId);
if (!ValidIdIn.IsValid() || UserId != ValidIdIn.GetUniqueNetId())
{
UE_LOG(LogNet, Warning, TEXT("UserId input %s != UserId output %s"), *UserId->ToString(), *ValidIdIn->ToString());
bSuccess = false;
}
if (bSuccess)
{
TArray<uint8> Buffer;
for (int32 i=0; i<2; i++)
{
Buffer.Empty();
FMemoryWriter TestWriteUniqueId(Buffer);
if (i == 0)
{
// Normal serialize
TestWriteUniqueId << EmptyIdIn;
TestWriteUniqueId << ValidIdIn;
}
else
{
// Net serialize
bool bSuccess = false;
EmptyIdIn.NetSerialize(TestWriteUniqueId, NULL, bSuccess);
ValidIdIn.NetSerialize(TestWriteUniqueId, NULL, bSuccess);
}
FMemoryReader TestReadUniqueId(Buffer);
FUniqueNetIdRepl EmptyIdOut;
TestReadUniqueId << EmptyIdOut;
if (EmptyIdOut.GetUniqueNetId().IsValid())
{
UE_LOG(LogNet, Warning, TEXT("EmptyId %s should have been invalid"), *EmptyIdOut->ToString());
bSuccess = false;
}
FUniqueNetIdRepl ValidIdOut;
TestReadUniqueId << ValidIdOut;
if (*UserId != *ValidIdOut.GetUniqueNetId())
{
UE_LOG(LogNet, Warning, TEXT("UserId input %s != UserId output %s"), *ValidIdIn->ToString(), *ValidIdOut->ToString());
bSuccess = false;
}
}
}
}
if (!bSuccess)
{
UE_LOG(LogNet, Warning, TEXT("TestUniqueIdRepl test failure!"));
}
}