UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ChunkData.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Memory/MemoryFwd.h"
5#include "Misc/SecureHash.h"
7#include "Misc/Guid.h"
9
10namespace BuildPatchServices
11{
12 class IFileSystem;
13
14 // Constant for the legacy fixed chunk window size, which was 1MiB.
15 static const uint32 LegacyFixedChunkWindow = 1024 * 1024;
16
21 {
22 None = 0x00,
23
24 // Flag for compressed data.
25 Compressed = 0x01,
26
27 // Flag for encrypted. If also compressed, decrypt first. Encryption will ruin compressibility.
28 Encrypted = 0x02,
29 };
30 ENUM_CLASS_FLAGS(EChunkStorageFlags);
31
36 {
37 None = 0x00,
38
39 // Flag for FRollingHash class used, stored in RollingHash on header.
40 RollingPoly64 = 0x01,
41
42 // Flag for FSHA1 class used, stored in SHAHash on header.
43 Sha1 = 0x02,
44 };
45 ENUM_CLASS_FLAGS(EChunkHashFlags);
46
51 {
52 Success = 0,
53
54 // Failed to open the file to load the chunk.
55 OpenFileFail,
56
57 // Could not serialize due to wrong archive type.
58 BadArchive,
59
60 // The header in the loaded chunk was invalid.
61 CorruptHeader,
62
63 // The expected file size in the header did not match the size of the file.
64 IncorrectFileSize,
65
66 // The storage type of the chunk is not one which we support.
67 UnsupportedStorage,
68
69 // The hash information was missing.
70 MissingHashInfo,
71
72 // The serialized data was not successfully understood.
73 SerializationError,
74
75 // The data was saved compressed but decompression failed.
76 DecompressFailure,
77
78 // The expected data hash in the header did not match the hash of the data.
79 HashCheckFailed,
80
81 // The size of the file is too big to handle
82 FileSizeTooBig,
83
84 // The operation was aborted.
86 };
87
91 const TCHAR* ToString(const EChunkLoadResult& ChunkLoadResult);
92
97 {
98 Success = 0,
99
100 // Failed to create the file for the chunk.
101 FileCreateFail,
102
103 // Could not serialize due to wrong archive type.
104 BadArchive,
105
106 // There was a serialization problem when writing to the chunk file.
107 SerializationError
108 };
109
113 const TCHAR* ToString(const EChunkSaveResult& ChunkSaveResult);
114
119 {
120 FChunkHeader();
128 // The version of this header data.
130 // The size of this header.
132 // The GUID for this data.
134 // The size of this data compressed.
136 // The size of this data uncompressed.
138 // How the chunk data is stored.
139 EChunkStorageFlags StoredAs;
140 // What type of hash we are using.
141 EChunkHashFlags HashType;
142 // The FRollingHash hashed value for this chunk data.
144 // The FSHA hashed value for this chunk data.
146 };
147
148 // Some helper constants for dealing with chunks that are full of one single byte, usually padding.
149 namespace PaddingChunk
150 {
151 // The A, B, and C components of a chunk Guid indicating that this is a padding chunk. D would be the actual byte padded with.
152 static const int32 ChunkIdA = 0x00000001;
153 static const int32 ChunkIdB = 0x00000000;
154 static const int32 ChunkIdC = 0x00000000;
155 // The size of the chunk we use to save out, which would allow a legacy client to actually use one.
156 static const uint32 ChunkSize = LegacyFixedChunkWindow;
162 {
163 return Guid.A == ChunkIdA && Guid.B == ChunkIdB && Guid.C == ChunkIdC && Guid.D >= 0 && Guid.D <= 255;
164 }
170 {
172 return Guid.D;
173 }
179 {
180 return FGuid(ChunkIdA, ChunkIdB, ChunkIdC, Byte);
181 }
182 }
183
188 {
189 FChunkPart();
190 FChunkPart(const FGuid& Guid, const uint32 Offset, const uint32 Size);
197 friend FArchive& operator<<(FArchive& Ar, FChunkPart& ChunkPart);
202 bool IsPadding() const
203 {
205 }
211 {
213 }
214 // The GUID of the chunk containing this part.
216 // The offset of the first byte into the chunk.
218 // The size of this part.
220 };
221
226 {
228 // The file containing this piece
229 FString Filename;
230 // The offset into the file of this piece
232 // The FChunkPart that can be salvaged from this file
234 };
235
240 {
241 FChunkInfo();
242 // The GUID for this data.
244 // The FRollingHash hashed value for this chunk data.
246 // The FSHA hashed value for this chunk data.
248 // The group number this chunk divides into.
250 // The window size for this chunk.
252 // The file download size for this chunk.
254 };
255
265
270 {
279 // The version of this header data.
281 // The size of this header.
283 // The size of the following data.
285 // The table of contents.
287 };
288
293 {
294 public:
295 virtual ~IChunkDataAccess() {}
296
302 virtual void GetDataLock(const uint8** OutChunkData, const FChunkHeader** OutChunkHeader) const = 0;
304
308 virtual void ReleaseDataLock() const = 0;
309 };
310
315 {
316 public:
323 };
324
330 {
331 public:
332 FScopeLockedChunkData(IChunkDataAccess* ChunkDataAccess);
334
338 FChunkHeader* GetHeader() const;
339
343 uint8* GetData() const;
344
345 private:
346 // The provided IChunkDataAccess which we lock and release.
347 IChunkDataAccess* ChunkDataAccess;
348 // Pointer to the header data.
349 FChunkHeader* ChunkHeader;
350 // Pointer to the chunk data.
351 uint8* ChunkData;
352 };
353
358 {
359 public:
361
368 virtual IChunkDataAccess* LoadFromFile(const FString& Filename, EChunkLoadResult& OutLoadResult) const = 0;
369
376 virtual IChunkDataAccess* LoadFromMemory(const TArray<uint8>& Memory, EChunkLoadResult& OutLoadResult) const = 0;
377
384 virtual IChunkDataAccess* LoadFromArchive(FArchive& Archive, EChunkLoadResult& OutLoadResult) const = 0;
385
392 virtual EChunkSaveResult SaveToFile(const FString& Filename, const IChunkDataAccess* ChunkDataAccess) const = 0;
393
400 virtual EChunkSaveResult SaveToMemory(TArray<uint8>& Memory, const IChunkDataAccess* ChunkDataAccess) const = 0;
401
408 virtual EChunkSaveResult SaveToArchive(FArchive& Archive, const IChunkDataAccess* ChunkDataAccess) const = 0;
409
410 // In performance sensitive situations, can request the serializer to save uncompressed if implemented
411 virtual EChunkSaveResult SaveToArchiveUncompressed(FArchive& Archive, const IChunkDataAccess* ChunkDataAccess) const
412 {
413 return SaveToArchive(Archive, ChunkDataAccess);
414 }
415
416 // Read the header from the archive, make sure it's sane, and set up to decompress/hash in a separate call. This
417 // is to allow the IO to be on a separate thread from decompression/hashing.
419
420 // Take the output of ValidateAndRead and process it in to an actual output chunk.
422
429 };
430
435 {
436 public:
437 static IChunkDataSerialization* Create(IFileSystem* FileSystem, EFeatureLevel FeatureLevel = EFeatureLevel::Latest);
438 };
439}
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ChunkData.h:293
virtual void GetDataLock(uint8 **OutChunkData, FChunkHeader **OutChunkHeader)=0
virtual ~IChunkDataAccess()
Definition ChunkData.h:295
virtual void ReleaseDataLock() const =0
virtual void GetDataLock(const uint8 **OutChunkData, const FChunkHeader **OutChunkHeader) const =0
virtual EChunkSaveResult SaveToFile(const FString &Filename, const IChunkDataAccess *ChunkDataAccess) const =0
virtual void InjectShaToChunkData(TArray< uint8 > &Memory, const FSHAHash &ShaHashData) const =0
virtual ~IChunkDataSerialization()
Definition ChunkData.h:360
virtual bool DecompressValidatedRead(const FChunkHeader &InHeader, FMutableMemoryView InDestionationBuffer, const FUniqueBuffer &InCompressedBuffer) const =0
virtual IChunkDataAccess * LoadFromMemory(const TArray< uint8 > &Memory, EChunkLoadResult &OutLoadResult) const =0
virtual bool ValidateAndRead(FArchive &InArchive, FMutableMemoryView InDestinationBuffer, FChunkHeader &OutHeader, FUniqueBuffer &OutCompressedBuffer) const =0
virtual EChunkSaveResult SaveToArchiveUncompressed(FArchive &Archive, const IChunkDataAccess *ChunkDataAccess) const
Definition ChunkData.h:411
virtual IChunkDataAccess * LoadFromArchive(FArchive &Archive, EChunkLoadResult &OutLoadResult) const =0
virtual EChunkSaveResult SaveToArchive(FArchive &Archive, const IChunkDataAccess *ChunkDataAccess) const =0
virtual EChunkSaveResult SaveToMemory(TArray< uint8 > &Memory, const IChunkDataAccess *ChunkDataAccess) const =0
virtual IChunkDataAccess * LoadFromFile(const FString &Filename, EChunkLoadResult &OutLoadResult) const =0
Definition FileSystem.h:51
EChunkStorageFlags
Definition ChunkData.h:21
EChunkHashFlags
Definition ChunkData.h:36
static const uint32 LegacyFixedChunkWindow
Definition ChunkData.h:15
EChunkSaveResult
Definition ChunkData.h:97
EChunkLoadResult
Definition ChunkData.h:51
Definition Archive.h:1208
Definition SecureHash.h:226
Definition SharedBuffer.h:218
Definition Array.h:670
FORCEINLINE FGuid MakePaddingGuid(uint8 Byte)
Definition ChunkData.h:178
FORCEINLINE bool IsPadding(const FGuid &Guid)
Definition ChunkData.h:161
FORCEINLINE uint8 GetPaddingByte(const FGuid &Guid)
Definition ChunkData.h:169
Definition BuildPatchFileConstructor.h:28
TArray< FChunkLocation > Contents
Definition ChunkData.h:286
uint64 DataSize
Definition ChunkData.h:284
FChunkDatabaseHeader()
Definition ChunkData.cpp:336
friend FArchive & operator<<(FArchive &Ar, FChunkDatabaseHeader &Header)
Definition ChunkData.cpp:343
uint32 HeaderSize
Definition ChunkData.h:282
uint32 Version
Definition ChunkData.h:280
Definition ChunkData.h:119
uint64 RollingHash
Definition ChunkData.h:143
EChunkStorageFlags StoredAs
Definition ChunkData.h:139
EChunkHashFlags HashType
Definition ChunkData.h:141
uint32 DataSizeCompressed
Definition ChunkData.h:135
FGuid Guid
Definition ChunkData.h:133
uint32 HeaderSize
Definition ChunkData.h:131
friend FArchive & operator<<(FArchive &Ar, FChunkHeader &Header)
Definition ChunkData.cpp:159
uint32 Version
Definition ChunkData.h:129
FSHAHash SHAHash
Definition ChunkData.h:145
FChunkHeader()
Definition ChunkData.cpp:148
uint32 DataSizeUncompressed
Definition ChunkData.h:137
Definition ChunkData.h:240
int64 FileSize
Definition ChunkData.h:253
uint64 Hash
Definition ChunkData.h:245
uint8 GroupNumber
Definition ChunkData.h:249
FSHAHash ShaHash
Definition ChunkData.h:247
FGuid Guid
Definition ChunkData.h:243
uint32 WindowSize
Definition ChunkData.h:251
FChunkInfo()
Definition ChunkData.cpp:243
Definition ChunkData.h:260
uint32 ByteSize
Definition ChunkData.h:263
uint64 ByteStart
Definition ChunkData.h:262
FGuid ChunkId
Definition ChunkData.h:261
Definition ChunkData.h:188
uint32 Offset
Definition ChunkData.h:217
FGuid Guid
Definition ChunkData.h:215
uint32 Size
Definition ChunkData.h:219
bool IsPadding() const
Definition ChunkData.h:202
FChunkPart()
Definition ChunkData.cpp:255
uint8 GetPaddingByte() const
Definition ChunkData.h:210
friend FArchive & operator<<(FArchive &Ar, FChunkPart &ChunkPart)
Definition ChunkData.cpp:269
Definition ChunkData.h:226
FChunkPart ChunkPart
Definition ChunkData.h:233
FString Filename
Definition ChunkData.h:229
FFileChunkPart()
Definition ChunkData.cpp:305
uint64 FileOffset
Definition ChunkData.h:231
uint8 * GetData() const
Definition ChunkData.cpp:427
FChunkHeader * GetHeader() const
Definition ChunkData.cpp:422
~FScopeLockedChunkData()
Definition ChunkData.cpp:417
Definition Guid.h:109