UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CompactBinaryPackage.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Containers/Array.h"
8#include "CoreTypes.h"
9#include "IO/IoHash.h"
11#include "Memory/SharedBuffer.h"
13#include "Misc/TVariant.h"
15#include "Templates/Function.h"
17
18class FArchive;
19class FCbWriter;
20template <typename FuncType> class TFunctionRef;
21
23
38{
39 struct FObjectValue
40 {
41 FCbObject Object;
43
44 CORE_API FObjectValue(FCbObject&& Object, const FIoHash* Hash);
45 };
46
47 struct FBinaryValue
48 {
51
53 inline explicit FBinaryValue(BufferType&& InBuffer)
54 : Buffer(Forward<BufferType>(InBuffer).MakeOwned())
56 {
57 }
58
60 inline explicit FBinaryValue(BufferType&& InBuffer, const FIoHash& InHash)
61 : Buffer(Forward<BufferType>(InBuffer).MakeOwned())
62 , Hash(InHash)
63 {
65 }
66 };
67
68 struct FCompressedBinaryValue
69 {
72
74 inline explicit FCompressedBinaryValue(BufferType&& InBuffer)
75 : Buffer(Forward<BufferType>(InBuffer).MakeOwned())
76 , Hash(Buffer.GetRawHash())
77 {
78 }
79
81 inline explicit FCompressedBinaryValue(BufferType&& InBuffer, const FIoHash& InHash)
82 : Buffer(Forward<BufferType>(InBuffer).MakeOwned())
83 , Hash(InHash)
84 {
85 }
86 };
87
88 template <typename... ArgTypes, decltype(FBinaryValue(DeclVal<ArgTypes>()...))* = nullptr>
91 {
92 if (Value.Get<FBinaryValue>().Buffer.IsNull())
93 {
94 Value.Emplace<TYPE_OF_NULLPTR>();
95 }
96 }
97
98public:
100 FCbAttachment() = default;
101
103 inline explicit FCbAttachment(const FCbObject& InValue)
104 : Value(TInPlaceType<FObjectValue>(), FCbObject(InValue), nullptr) {}
105 inline explicit FCbAttachment(FCbObject&& InValue)
106 : Value(TInPlaceType<FObjectValue>(), MoveTemp(InValue), nullptr) {}
107 inline explicit FCbAttachment(const FCbObject& InValue, const FIoHash& Hash)
108 : Value(TInPlaceType<FObjectValue>(), FCbObject(InValue), &Hash) {}
109 inline explicit FCbAttachment(FCbObject&& InValue, const FIoHash& Hash)
110 : Value(TInPlaceType<FObjectValue>(), MoveTemp(InValue), &Hash) {}
111
114 inline explicit FCbAttachment(BufferType&& InValue)
115 : FCbAttachment(TInPlaceType<FBinaryValue>(), Forward<BufferType>(InValue).MakeOwned()) {}
117 inline explicit FCbAttachment(BufferType&& InValue, const FIoHash& InHash)
118 : FCbAttachment(TInPlaceType<FBinaryValue>(), Forward<BufferType>(InValue).MakeOwned(), InHash) {}
119
122 : Value(TInPlaceType<FCompressedBinaryValue>(), InValue)
123 {
124 if (Value.Get<FCompressedBinaryValue>().Buffer.IsNull())
125 {
126 Value.Emplace<TYPE_OF_NULLPTR>();
127 }
128 }
129
131 : Value(TInPlaceType<FCompressedBinaryValue>(), InValue, Hash)
132 {
133 if (Value.Get<FCompressedBinaryValue>().Buffer.IsNull())
134 {
135 Value.Emplace<TYPE_OF_NULLPTR>();
136 }
137 }
138
140 : Value(TInPlaceType<FCompressedBinaryValue>(), InValue)
141 {
142 if (Value.Get<FCompressedBinaryValue>().Buffer.IsNull())
143 {
144 Value.Emplace<TYPE_OF_NULLPTR>();
145 }
146 }
147
149 : Value(TInPlaceType<FCompressedBinaryValue>(), InValue, Hash)
150 {
151 if (Value.Get<FCompressedBinaryValue>().Buffer.IsNull())
152 {
153 Value.Emplace<TYPE_OF_NULLPTR>();
154 }
155 }
156
158 inline void Reset() { *this = FCbAttachment(); }
159
161 inline FCbObject AsObject() const;
162
164 inline FSharedBuffer AsBinary() const;
165
167 inline const FCompositeBuffer& AsCompositeBinary() const;
168
170 inline const FCompressedBuffer& AsCompressedBinary() const;
171
173 inline explicit operator bool() const { return !IsNull(); }
174
176 inline bool IsNull() const { return Value.IsType<TYPE_OF_NULLPTR>(); }
177
179 inline bool IsObject() const { return Value.IsType<FObjectValue>(); }
180
182 inline bool IsBinary() const { return Value.IsType<FBinaryValue>(); }
183
185 inline bool IsCompressedBinary() const { return Value.IsType<FCompressedBinaryValue>(); }
186
188 CORE_API FIoHash GetHash() const;
189
191 inline bool operator==(const FCbAttachment& Attachment) const { return GetHash() == Attachment.GetHash(); }
192 inline bool operator!=(const FCbAttachment& Attachment) const { return GetHash() != Attachment.GetHash(); }
193 inline bool operator<(const FCbAttachment& Attachment) const { return GetHash() < Attachment.GetHash(); }
194
202 CORE_API bool TryLoad(FCbFieldIterator& Fields);
203
214
216 CORE_API void Save(FCbWriter& Writer) const;
217
219 CORE_API void Save(FArchive& Ar) const;
220
221private:
223};
224
226inline uint32 GetTypeHash(const FCbAttachment& Attachment)
227{
228 return GetTypeHash(Attachment.GetHash());
229}
230
232
256{
257public:
264
266 FCbPackage() = default;
267
273 inline explicit FCbPackage(FCbObject InObject)
274 {
275 SetObject(MoveTemp(InObject));
276 }
277
285 {
286 SetObject(MoveTemp(InObject), InResolver);
287 }
288
295 inline explicit FCbPackage(FCbObject InObject, const FIoHash& InObjectHash)
296 {
297 SetObject(MoveTemp(InObject), InObjectHash);
298 }
299
308 {
310 }
311
313 inline void Reset() { *this = FCbPackage(); }
314
316 inline explicit operator bool() const { return !IsNull(); }
317
319 inline bool IsNull() const { return !Object && Attachments.IsEmpty(); }
320
322 inline const FCbObject& GetObject() const { return Object; }
323
325 inline const FIoHash& GetObjectHash() const { return ObjectHash; }
326
332 inline void SetObject(FCbObject InObject)
333 {
334 SetObject(MoveTemp(InObject), nullptr, nullptr);
335 }
336
344 {
345 SetObject(MoveTemp(InObject), nullptr, &InResolver);
346 }
347
354 inline void SetObject(FCbObject InObject, const FIoHash& InObjectHash)
355 {
356 SetObject(MoveTemp(InObject), &InObjectHash, nullptr);
357 }
358
367 {
369 }
370
372 inline TConstArrayView<FCbAttachment> GetAttachments() const { return Attachments; }
373
380 CORE_API const FCbAttachment* FindAttachment(const FIoHash& Hash) const;
381
383 inline const FCbAttachment* FindAttachment(const FCbAttachment& Attachment) const
384 {
385 return FindAttachment(Attachment.GetHash());
386 }
387
389 inline void AddAttachment(const FCbAttachment& Attachment)
390 {
391 AddAttachment(Attachment, nullptr);
392 }
393
395 inline void AddAttachment(const FCbAttachment& Attachment, FAttachmentResolver Resolver)
396 {
397 AddAttachment(Attachment, &Resolver);
398 }
399
406 inline int32 RemoveAttachment(const FCbAttachment& Attachment) { return RemoveAttachment(Attachment.GetHash()); }
407
409 CORE_API bool Equals(const FCbPackage& Package) const;
410 inline bool operator==(const FCbPackage& Package) const { return Equals(Package); }
411 inline bool operator!=(const FCbPackage& Package) const { return !Equals(Package); }
412
421 CORE_API bool TryLoad(FCbFieldIterator& Fields);
422
433
435 CORE_API void Save(FCbWriter& Writer) const;
436
438 CORE_API void Save(FArchive& Ar) const;
439
440private:
441 CORE_API void SetObject(FCbObject Object, const FIoHash* Hash, FAttachmentResolver* Resolver);
442 CORE_API void AddAttachment(const FCbAttachment& Attachment, FAttachmentResolver* Resolver);
443
444 void GatherAttachments(const FCbObject& Object, FAttachmentResolver Resolver);
445
447 TArray<FCbAttachment> Attachments;
448 FCbObject Object;
449 FIoHash ObjectHash;
450};
451
453
455{
456 if (const FObjectValue* ObjectValue = Value.TryGet<FObjectValue>())
457 {
458 return ObjectValue->Object;
459 }
460 return FCbObject();
461}
462
464{
465 if (const FBinaryValue* BinaryValue = Value.TryGet<FBinaryValue>())
466 {
467 return BinaryValue->Buffer.ToShared();
468 }
469 return FSharedBuffer();
470}
471
473{
474 if (const FBinaryValue* BinaryValue = Value.TryGet<FBinaryValue>())
475 {
476 return BinaryValue->Buffer;
477 }
479}
480
482{
483 if (const FCompressedBinaryValue* CompressedBuffer = Value.TryGet<FCompressedBinaryValue>())
484 {
485 return CompressedBuffer->Buffer;
486 }
488}
#define checkSlow(expr)
Definition AssertionMacros.h:332
uint32 GetTypeHash(const FCbAttachment &Attachment)
Definition CompactBinaryPackage.h:226
#define UE_INTERNAL
Definition CoreMiscDefines.h:345
FPlatformTypes::TYPE_OF_NULLPTR TYPE_OF_NULLPTR
The type of the C++ nullptr keyword.
Definition Platform.h:1157
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition CompactBinaryPackage.h:38
UE_INTERNAL FCbAttachment(FCompressedBuffer &&InValue, const FIoHash &Hash)
Definition CompactBinaryPackage.h:148
FCbAttachment(FCompressedBuffer &&InValue)
Definition CompactBinaryPackage.h:139
FCbAttachment(const FCbObject &InValue, const FIoHash &Hash)
Definition CompactBinaryPackage.h:107
const FCompositeBuffer & AsCompositeBinary() const
Definition CompactBinaryPackage.h:472
void Reset()
Definition CompactBinaryPackage.h:158
FCbAttachment()=default
bool operator==(const FCbAttachment &Attachment) const
Definition CompactBinaryPackage.h:191
bool IsNull() const
Definition CompactBinaryPackage.h:176
const FCompressedBuffer & AsCompressedBinary() const
Definition CompactBinaryPackage.h:481
bool IsBinary() const
Definition CompactBinaryPackage.h:182
FCbAttachment(FCbObject &&InValue)
Definition CompactBinaryPackage.h:105
FCbObject AsObject() const
Definition CompactBinaryPackage.h:454
bool operator<(const FCbAttachment &Attachment) const
Definition CompactBinaryPackage.h:193
CORE_API FIoHash GetHash() const
Definition CompactBinaryPackage.cpp:89
FSharedBuffer AsBinary() const
Definition CompactBinaryPackage.h:463
UE_INTERNAL FCbAttachment(const FCompressedBuffer &InValue, const FIoHash &Hash)
Definition CompactBinaryPackage.h:130
CORE_API bool TryLoad(FCbFieldIterator &Fields)
Definition CompactBinaryPackage.cpp:109
bool operator!=(const FCbAttachment &Attachment) const
Definition CompactBinaryPackage.h:192
FCbAttachment(const FCompressedBuffer &InValue)
Definition CompactBinaryPackage.h:121
FCbAttachment(BufferType &&InValue, const FIoHash &InHash)
Definition CompactBinaryPackage.h:117
FCbAttachment(const FCbObject &InValue)
Definition CompactBinaryPackage.h:103
FCbAttachment(BufferType &&InValue)
Definition CompactBinaryPackage.h:114
bool IsCompressedBinary() const
Definition CompactBinaryPackage.h:185
bool IsObject() const
Definition CompactBinaryPackage.h:179
FCbAttachment(FCbObject &&InValue, const FIoHash &Hash)
Definition CompactBinaryPackage.h:109
Definition CompactBinary.h:1288
Definition CompactBinary.h:1392
Definition CompactBinaryPackage.h:256
FCbPackage(FCbObject InObject, FAttachmentResolver InResolver)
Definition CompactBinaryPackage.h:284
CORE_API bool TryLoad(FCbFieldIterator &Fields)
Definition CompactBinaryPackage.cpp:295
bool operator==(const FCbPackage &Package) const
Definition CompactBinaryPackage.h:410
int32 RemoveAttachment(const FCbAttachment &Attachment)
Definition CompactBinaryPackage.h:406
FCbPackage()=default
const FCbAttachment * FindAttachment(const FCbAttachment &Attachment) const
Definition CompactBinaryPackage.h:383
void SetObject(FCbObject InObject, const FIoHash &InObjectHash)
Definition CompactBinaryPackage.h:354
const FCbObject & GetObject() const
Definition CompactBinaryPackage.h:322
FCbPackage(FCbObject InObject)
Definition CompactBinaryPackage.h:273
FCbPackage(FCbObject InObject, const FIoHash &InObjectHash)
Definition CompactBinaryPackage.h:295
TFunctionRef< FSharedBuffer(const FIoHash &Hash)> FAttachmentResolver
Definition CompactBinaryPackage.h:263
void Reset()
Definition CompactBinaryPackage.h:313
bool IsNull() const
Definition CompactBinaryPackage.h:319
void SetObject(FCbObject InObject)
Definition CompactBinaryPackage.h:332
TConstArrayView< FCbAttachment > GetAttachments() const
Definition CompactBinaryPackage.h:372
void SetObject(FCbObject InObject, const FIoHash &InObjectHash, FAttachmentResolver InResolver)
Definition CompactBinaryPackage.h:366
const FIoHash & GetObjectHash() const
Definition CompactBinaryPackage.h:325
CORE_API int32 RemoveAttachment(const FIoHash &Hash)
Definition CompactBinaryPackage.cpp:254
CORE_API const FCbAttachment * FindAttachment(const FIoHash &Hash) const
Definition CompactBinaryPackage.cpp:270
FCbPackage(FCbObject InObject, const FIoHash &InObjectHash, FAttachmentResolver InResolver)
Definition CompactBinaryPackage.h:307
bool operator!=(const FCbPackage &Package) const
Definition CompactBinaryPackage.h:411
void AddAttachment(const FCbAttachment &Attachment)
Definition CompactBinaryPackage.h:389
void SetObject(FCbObject InObject, FAttachmentResolver InResolver)
Definition CompactBinaryPackage.h:343
void AddAttachment(const FCbAttachment &Attachment, FAttachmentResolver Resolver)
Definition CompactBinaryPackage.h:395
Definition CompactBinaryWriter.h:68
Definition CompositeBuffer.h:27
static CORE_API const FCompositeBuffer Null
Definition CompositeBuffer.h:128
Definition CompressedBuffer.h:50
static CORE_API const FCompressedBuffer Null
Definition CompressedBuffer.h:168
Definition SharedBuffer.h:341
static CORE_API FUniqueBuffer Alloc(uint64 Size)
Definition SharedBuffer.cpp:103
Definition Array.h:670
UE_REWRITE bool IsEmpty() const
Definition Array.h:1133
Definition AssetRegistryState.h:50
Definition TVariant.h:48
void Emplace(ArgTypes &&... Args)
Definition TVariant.h:211
U & Get() UE_LIFETIMEBOUND
Definition TVariant.h:146
U * TryGet() UE_LIFETIMEBOUND
Definition TVariant.h:174
bool IsType() const
Definition TVariant.h:138
Definition IoHash.h:33
static FIoHash HashBuffer(FMemoryView View)
Definition IoHash.h:156
Definition TVariant.h:13