UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IoChunkId.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
7#include "Memory/MemoryView.h"
8#include "Misc/ByteSwap.h"
9#include "String/BytesToHex.h"
10
11class FArchive;
12class FCbFieldView;
13class FCbWriter;
14class FPackageId;
15class FIoContainerId;
16
27enum class EIoChunkType : uint8
28{
29 Invalid = 0,
31 BulkData = 2,
34 ScriptObjects = 5,
36 ExternalFile = 7,
38 ShaderCode = 9,
40 DerivedData = 11,
42 PackageResource = 13,
43 MAX
44};
45
46CORE_API FString LexToString(const EIoChunkType Type);
47
48inline bool IsBulkDataType(const EIoChunkType Type)
49{
51 {
52 return true;
53 }
54 else
55 {
56 return false;
57 }
58}
59
64{
65public:
67
69 {
70 uint32 Hash = 5381;
71 for (int i = 0; i < sizeof Id; ++i)
72 {
73 Hash = Hash * 33 + InId.Id[i];
74 }
75 return Hash;
76 }
77
78 friend CORE_API FArchive& operator<<(FArchive& Ar, FIoChunkId& ChunkId);
79 friend CORE_API FCbWriter& operator<<(FCbWriter& Writer, const FIoChunkId& ChunkId);
81
82 template <typename CharType>
84 {
85 UE::String::BytesToHexLower(ChunkId.Id, Builder);
86 return Builder;
87 }
88
89 CORE_API void ToString(FString& Output) const;
90 friend CORE_API FString LexToString(const FIoChunkId& Id);
91
92 inline bool operator ==(const FIoChunkId& Rhs) const
93 {
94 return 0 == FMemory::Memcmp(Id, Rhs.Id, sizeof Id);
95 }
96
97 inline bool operator !=(const FIoChunkId& Rhs) const
98 {
99 return !(*this == Rhs);
100 }
101
102 inline bool operator <(const FIoChunkId& Rhs) const
103 {
104 return FMemory::Memcmp(Id, Rhs.Id, sizeof Id) < 0;
105 }
106
107 inline bool operator >(const FIoChunkId& Rhs) const
108 {
109 return FMemory::Memcmp(Id, Rhs.Id, sizeof Id) > 0;
110 }
111
112 void Set(const void* InIdPtr, SIZE_T InSize)
113 {
114 check(InSize == sizeof Id);
115 FMemory::Memcpy(Id, InIdPtr, sizeof Id);
116 }
117
119 {
120 check(InView.GetSize() == sizeof Id);
121 FMemory::Memcpy(Id, InView.GetData(), sizeof Id);
122 }
123
124 inline bool IsValid() const
125 {
126 return *this != InvalidChunkId;
127 }
128
129 inline const uint8* GetData() const { return Id; }
130 inline uint32 GetSize() const { return sizeof Id; }
131
133 {
134 return static_cast<EIoChunkType>(Id[11]);
135 }
136
137 friend class FIoStoreReaderImpl;
138
144
145private:
146 static inline FIoChunkId CreateEmptyId()
147 {
148 FIoChunkId ChunkId;
149 uint8 Data[12] = { 0 };
150 ChunkId.Set(Data, sizeof Data);
151
152 return ChunkId;
153 }
154
155 uint8 Id[12];
156};
157
158
161{
162 checkSlow(IoChunkType != EIoChunkType::ExternalFile); // Use CreateExternalFileChunkId() instead
163 checkfSlow(IsBulkDataType(IoChunkType) == false, TEXT("Bulkdata types should call CreateBulkDataIoChunkId instead"));
164
165 uint8 Data[12] = {0};
166
167 *reinterpret_cast<uint64*>(&Data[0]) = ChunkId;
168 *reinterpret_cast<uint16*>(&Data[8]) = NETWORK_ORDER16(ChunkIndex);
169 *reinterpret_cast<uint8*>(&Data[11]) = static_cast<uint8>(IoChunkType);
170
172 IoChunkId.Set(Data, 12);
173
174 return IoChunkId;
175}
176
177
178
190{
191 checkSlow(IoChunkType != EIoChunkType::ExternalFile); // Use CreateExternalFileChunkId() instead
192 checkfSlow(IsBulkDataType(IoChunkType), TEXT("CreateBulkDataIoChunkId is only intended for bulkdata types"));
193
194 uint8 Data[12] = { 0 };
195
196 *reinterpret_cast<uint64*>(&Data[0]) = ChunkId;
197 *reinterpret_cast<uint16*>(&Data[8]) = NETWORK_ORDER16(ChunkIndex);
198 *reinterpret_cast<uint8*>(&Data[10]) = ChunkGroup;
199 *reinterpret_cast<uint8*>(&Data[11]) = static_cast<uint8>(IoChunkType);
200
202 IoChunkId.Set(Data, 12);
203
204 return IoChunkId;
205}
206
209
212
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define check(expr)
Definition AssertionMacros.h:314
#define NETWORK_ORDER16(x)
Definition ByteSwap.h:144
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
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
FIoChunkId CreateBulkDataIoChunkId(uint64 ChunkId, uint16 ChunkIndex, uint8 ChunkGroup, EIoChunkType IoChunkType)
Definition IoChunkId.h:189
FIoChunkId CreateIoChunkId(uint64 ChunkId, uint16 ChunkIndex, EIoChunkType IoChunkType)
Definition IoChunkId.h:160
CORE_API FIoChunkId CreateExternalFileChunkId(const FStringView Filename)
Definition IoChunkId.cpp:95
CORE_API FString LexToString(const EIoChunkType Type)
Definition IoChunkId.cpp:12
bool IsBulkDataType(const EIoChunkType Type)
Definition IoChunkId.h:48
EIoChunkType
Definition IoChunkId.h:28
CORE_API FIoChunkId CreateContainerHeaderChunkId(const FIoContainerId &ContainerId)
Definition IoChunkId.cpp:125
CORE_API FIoChunkId CreatePackageDataChunkId(const FPackageId &PackageId)
Definition IoChunkId.cpp:90
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition CompactBinary.h:610
Definition CompactBinaryWriter.h:68
Definition IoChunkId.h:64
friend TStringBuilderBase< CharType > & operator<<(TStringBuilderBase< CharType > &Builder, const FIoChunkId &ChunkId)
Definition IoChunkId.h:83
friend CORE_API FArchive & operator<<(FArchive &Ar, FIoChunkId &ChunkId)
Definition IoChunkId.cpp:71
const uint8 * GetData() const
Definition IoChunkId.h:129
void Set(const void *InIdPtr, SIZE_T InSize)
Definition IoChunkId.h:112
void Set(FMemoryView InView)
Definition IoChunkId.h:118
uint32 GetSize() const
Definition IoChunkId.h:130
bool IsValid() const
Definition IoChunkId.h:124
bool operator==(const FIoChunkId &Rhs) const
Definition IoChunkId.h:92
bool operator<(const FIoChunkId &Rhs) const
Definition IoChunkId.h:102
bool operator>(const FIoChunkId &Rhs) const
Definition IoChunkId.h:107
friend uint32 GetTypeHash(FIoChunkId InId)
Definition IoChunkId.h:68
bool operator!=(const FIoChunkId &Rhs) const
Definition IoChunkId.h:97
friend CORE_API FString LexToString(const FIoChunkId &Id)
Definition IoChunkId.cpp:43
static CORE_API const FIoChunkId InvalidChunkId
Definition IoChunkId.h:66
static CORE_API FIoChunkId FromHex(FStringView Hex)
Definition IoChunkId.cpp:59
EIoChunkType GetChunkType() const
Definition IoChunkId.h:132
friend CORE_API bool LoadFromCompactBinary(FCbFieldView Field, FIoChunkId &OutChunkId)
Definition IoChunkId.cpp:83
Definition IoContainerId.h:18
Definition IoStore.cpp:316
Definition PackageId.h:19
Definition StringBuilder.h:79
Definition FieldSystemNoiseAlgo.cpp:6
void BytesToHexLower(TConstArrayView< uint8 > Bytes, ANSICHAR *OutHex)
Definition BytesToHex.cpp:42
static UE_FORCEINLINE_HINT int32 Memcmp(const void *Buf1, const void *Buf2, SIZE_T Count)
Definition UnrealMemory.h:114
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160