Files
UnrealEngineUWP/Engine/Source/Developer/Zen/Internal/ZenSerialization.cpp
Zousar Shaker 77f51a02b9 [Backout] - CL20433163
#fyi Zousar.Shaker
Original CL Desc
-----------------------------------------------------------------
Switch Zen cache store to use the HTTP request codepath in the Jupiter cache store while taking some of the improvements that had been made when that code was branched off to make the Zen HTTP codepath.  This is a precursor for getting Zen cache store using non-blocking operations like Jupiter cache store - this has started to be stubbed in with the EnqueueAsyncRpc methods that are stubbed in but not used from the Zen cache store.  Eventually I'd like this HTTP code to move out of the DerivedDataCache module and be usable elsewhere and supplant the HTTP code currently in the Zen module, but this will require some decisions about whether IRequestOwner should move out of the DerivedDataCache module or not.

Tested Zen operation using ShooterGame editor.
Tested Jupiter operation using CitySample editor (empty local cache).

#rb devin.doucette
#fyi stefan.boberg
#preflight 62953e65401169f78c57c298

[CL 20433363 by Zousar Shaker in ue5-main branch]
2022-05-30 19:32:59 -04:00

123 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ZenSerialization.h"
#include "Serialization/CompactBinary.h"
#include "Serialization/CompactBinaryPackage.h"
#include "Serialization/CompactBinarySerialization.h"
#include "Serialization/CompactBinaryValidation.h"
#include "Serialization/CompactBinaryWriter.h"
#if UE_WITH_ZEN
namespace UE::Zen {
void SaveCbAttachment(const FCbAttachment& Attachment, FCbWriter& Writer)
{
if (Attachment.IsCompressedBinary())
{
Writer.AddBinary(Attachment.AsCompressedBinary().GetCompressed());
Writer.AddBinaryAttachment(Attachment.GetHash());
}
else if (Attachment.IsNull())
{
Writer.AddBinary(FMemoryView());
}
else
{
// NOTE: All attachments needs to be compressed
checkNoEntry();
}
}
void SaveCbPackage(const FCbPackage& Package, FCbWriter& Writer)
{
if (const FCbObject& RootObject = Package.GetObject())
{
Writer.AddObject(RootObject);
Writer.AddObjectAttachment(Package.GetObjectHash());
}
for (const FCbAttachment& Attachment : Package.GetAttachments())
{
SaveCbAttachment(Attachment, Writer);
}
Writer.AddNull();
}
void SaveCbPackage(const FCbPackage& Package, FArchive& Ar)
{
FCbWriter Writer;
SaveCbPackage(Package, Writer);
Writer.Save(Ar);
}
bool TryLoadCbPackage(FCbPackage& Package, FArchive& Ar, FCbBufferAllocator Allocator)
{
uint8 StackBuffer[64];
const auto StackAllocator = [&Allocator, &StackBuffer](uint64 Size) -> FUniqueBuffer
{
return Size <= sizeof(StackBuffer) ? FUniqueBuffer::MakeView(StackBuffer, Size) : Allocator(Size);
};
Package = FCbPackage();
for (;;)
{
FCbField ValueField = LoadCompactBinary(Ar, StackAllocator);
if (!ValueField)
{
Ar.SetError();
return false;
}
if (ValueField.IsNull())
{
return true;
}
else if (ValueField.IsBinary())
{
const FMemoryView View = ValueField.AsBinaryView();
if (View.GetSize() > 0)
{
FSharedBuffer Buffer = FSharedBuffer::MakeView(View, ValueField.GetOuterBuffer()).MakeOwned();
FCbField HashField = LoadCompactBinary(Ar, StackAllocator);
const FIoHash& Hash = HashField.AsAttachment();
if (HashField.HasError() || FIoHash::HashBuffer(Buffer) != Hash)
{
Ar.SetError();
return false;
}
if (HashField.IsObjectAttachment())
{
Package.AddAttachment(FCbAttachment(FCbObject(MoveTemp(Buffer)), Hash));
}
else
{
Package.AddAttachment(FCbAttachment(FCompositeBuffer(MoveTemp(Buffer)), Hash));
}
}
}
else
{
FCbObject Object = ValueField.AsObject();
if (ValueField.HasError())
{
Ar.SetError();
return false;
}
if (Object)
{
FCbField HashField = LoadCompactBinary(Ar, StackAllocator);
FIoHash ObjectHash = HashField.AsObjectAttachment();
if (HashField.HasError() || Object.GetHash() != ObjectHash)
{
Ar.SetError();
return false;
}
Package.SetObject(Object, ObjectHash);
}
}
}
}
}
#endif // UE_WITH_ZEN