5#include "Containers/StringFwd.h"
6#include "Containers/StringView.h"
8#include "HAL/UnrealMemory.h"
10#include "Memory/CompositeBuffer.h"
11#include "Memory/MemoryFwd.h"
12#include "Memory/MemoryView.h"
13#include "Memory/SharedBuffer.h"
14#include "Misc/AssertionMacros.h"
15#include "Misc/EnumClassFlags.h"
16#include "String/BytesToHex.h"
17#include "Templates/Function.h"
18#include "Templates/IsTriviallyDestructible.h"
19#include "Templates/RemoveReference.h"
20#include "Templates/UnrealTemplate.h"
22template <
typename CharType>
class TStringBuilderBase;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
87template <
typename FuncType>
class TFunctionRef;
90using FCbBufferAllocator = TFunctionRef<FUniqueBuffer (uint64 Size)>;
95
96
97
98
99
100
110
111
112
113
116
117
118
119
120
124
125
126
127
130
131
132
133
134
144
145
146
147
150
151
152
153
167
168
169
170
173
174
175
176
185
186
187
188
191
192
193
194
198
199
200
201
205
206
207
208
209
212
213
214
215
216
223
224
225
226
227
333
334
335
336
337
338
339
340template <
typename FieldType>
356 constexpr inline FieldType&
operator*() {
return *
this; }
357 constexpr inline FieldType*
operator->() {
return this; }
370 using FieldType::Equals;
372 template <
typename OtherFieldType>
375 return FieldType::GetValueData() == Other.OtherFieldType::GetValueData() &&
FieldsEnd == Other.FieldsEnd;
378 template <
typename OtherFieldType>
381 return Equals(Other);
384 template <
typename OtherFieldType>
387 return !Equals(Other);
403
404
405
406
407
426 : FieldType(MoveTemp(InField))
432
433
434
435
436
438 : FieldType(MoveTemp(InField))
444 template <
typename OtherFieldType>
451 template <
typename OtherType>
474
475
476
477
481 using ByteArray = uint8[12];
487 inline explicit FCbObjectId(
const ByteArray& ObjectId);
518 return *
reinterpret_cast<
const uint32*>(&Id);
522 template <
typename CharType>
523 friend inline TStringBuilderBase<CharType>&
operator<<(TStringBuilderBase<CharType>& Builder,
const FCbObjectId& Id)
573template <
typename IntType>
577 Params
.IsSigned = IntType(-1) < IntType(0);
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
613
614
615
616
617
633 constexpr inline FUtf8StringView
GetName()
const
635 return FUtf8StringView(
static_cast<
const UTF8CHAR*>(Value) - NameLen, NameLen);
654 inline int8
AsInt8(int8 Default = 0) {
return AsInteger<int8>(Default); }
656 inline int16
AsInt16(int16 Default = 0) {
return AsInteger<int16>(Default); }
658 inline int32
AsInt32(int32 Default = 0) {
return AsInteger<int32>(Default); }
660 inline int64
AsInt64(int64 Default = 0) {
return AsInteger<int64>(Default); }
662 inline uint8
AsUInt8(uint8 Default = 0) {
return AsInteger<uint8>(Default); }
664 inline uint16
AsUInt16(uint16 Default = 0) {
return AsInteger<uint16>(Default); }
666 inline uint32
AsUInt32(uint32 Default = 0) {
return AsInteger<uint32>(Default); }
668 inline uint64
AsUInt64(uint64 Default = 0) {
return AsInteger<uint64>(Default); }
758
759
760
761
762
780
781
782
783
784
785
786
787
791 void CopyTo(FMutableMemoryView Buffer)
const;
800
801
802
803
804
853 static_assert(TIsTriviallyDestructible<FCbFieldView>::Value,
854 "This optimization requires FCbFieldView to be trivially destructible!");
855 new(
this) FCbFieldView(InData, InType);
860
861
862
863
864 template <
typename IntType>
884
885
886
887
894 return FCbFieldViewIterator(Field);
898
899
900
901
902
905 return !View.IsEmpty() ? FCbFieldViewIterator(FCbFieldView(View.GetData(), Type), View.GetDataEnd()) : FCbFieldViewIterator();
912 template <
typename OtherFieldType>
930
931
932
933
934
935
936
937
968
969
970
971
972
973
974
975
979 void CopyTo(FMutableMemoryView Buffer)
const;
985 inline void IterateAttachments(FCbFieldVisitor Visitor)
const { CreateViewIterator().IterateRangeAttachments(Visitor); }
988
989
990
991
992
995 return !FCbFieldView::HasName() && FCbFieldView::TryGetView(OutView);
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1031
1032
1033
1034
1035
1036
1037
1038
1065
1066
1067
1068
1069
1070
1071
1072
1076 void CopyTo(FMutableMemoryView Buffer)
const;
1082 inline void IterateAttachments(FCbFieldVisitor Visitor)
const { CreateViewIterator().IterateRangeAttachments(Visitor); }
1085
1086
1087
1088
1089
1092 return !FCbFieldView::HasName() && FCbFieldView::TryGetView(OutView);
1108template <
typename ViewType>
1116
1117
1118
1119
1120
1132 inline TCbBuffer(
const ViewType& Value, FSharedBuffer OuterBuffer)
1143 template <
typename OtherViewType>
1168 inline const ViewType&
AsView()
const {
return *
this; }
1171
1172
1173
1174
1175
1190 template <
typename OtherType>
1199
1200
1201
1202
1203
1204template <
typename Type,
typename ViewType>
1209 static inline Type
Clone(
const void*
const Data)
1215 static inline Type
Clone(
const ViewType& Value)
1223 static inline Type
MakeView(
const void*
const Data, FSharedBuffer OuterBuffer = FSharedBuffer())
1229 static inline Type
MakeView(
const ViewType& Value, FSharedBuffer OuterBuffer = FSharedBuffer())
1243
1244
1245
1246
1247
1269template <
typename ViewType>
1272 if (FCbFieldView Field = ViewType::operator[](Name))
1274 return FCbField::MakeView(Field, GetOuterBuffer());
1280
1281
1282
1283
1303
1304
1305
1306
1307
1310 if (Buffer.GetSize())
1312 const void*
const DataEnd = Buffer.GetView().GetDataEnd();
1313 return FCbFieldIterator(FCbField(MoveTemp(Buffer), Type), DataEnd);
1321 return FCbFieldIterator(FCbField(It, MoveTemp(OuterBuffer)), GetFieldsEnd(It));
1340template <
typename ViewType>
1343 if (FCbFieldViewIterator It = ViewType::CreateViewIterator())
1345 return FCbFieldIterator::MakeRangeView(It, GetOuterBuffer());
1347 return FCbFieldIterator();
1350template <
typename ViewType>
1353 return CreateIterator();
1359
1360
1361
1362
1363
1370 inline FCbField AsField()
const & {
return FCbField(FCbArrayView::AsFieldView(), *
this); }
1371 inline FCbField AsField() && {
return FCbField(FCbArrayView::AsFieldView(), MoveTemp(*
this)); }
1380
1381
1382
1383
1384
1395 return FCbField(Field, *
this);
1405 return FCbField(Field, *
this);
1414 inline FCbField AsField()
const & {
return FCbField(FCbObjectView::AsFieldView(), *
this); }
1415 inline FCbField AsField() && {
return FCbField(FCbObjectView::AsFieldView(), MoveTemp(*
this)); }
1445 const FMemoryView View = AsBinaryView();
1446 return !HasError() ? FSharedBuffer::MakeView(View, GetOuterBuffer()) : Default;
1451 const FMemoryView View = AsBinaryView();
1452 return !HasError() ? FSharedBuffer::MakeView(View, MoveTemp(*
this).GetOuterBuffer()) : Default;
#define ENUM_CLASS_FLAGS(Enum)
FCompositeBuffer GetBuffer() const
FCbField AsField() const &
bool Equals(const FCbArrayView &Other) const
FCbArrayView(const FCbFieldView &Field)
void IterateAttachments(FCbFieldVisitor Visitor) const
FCbFieldView AsFieldView() const
void CopyTo(FMutableMemoryView Buffer) const
void CopyTo(FArchive &Ar) const
static FCbArrayView FromFieldNoCheck(const FCbFieldView &Field)
void AppendHash(FIoHashBuilder &Builder) const
bool TryGetView(FMemoryView &OutView) const
FCompositeBuffer GetBuffer() const
FSharedBuffer AsBinary(const FSharedBuffer &Default=FSharedBuffer()) &&
FSharedBuffer AsBinary(const FSharedBuffer &Default=FSharedBuffer()) &
static FCbFieldIterator CloneRange(const FCbFieldViewIterator &It)
static FCbFieldIterator MakeRangeView(const FCbFieldViewIterator &It, FSharedBuffer OuterBuffer=FSharedBuffer())
static FCbFieldIterator MakeRange(FSharedBuffer Buffer, ECbFieldType Type=ECbFieldType::HasFieldType)
static FCbFieldIterator MakeSingle(FCbField Field)
constexpr FCbFieldIterator()=default
static FCbFieldIterator CloneRange(const FCbFieldIterator &It)
static constexpr ECbFieldType GetType(ECbFieldType Type)
static constexpr bool IsTimeSpan(ECbFieldType Type)
static constexpr bool IsArray(ECbFieldType Type)
static constexpr ECbFieldType ArrayMask
static constexpr bool IsObjectId(ECbFieldType Type)
static void StaticAssertTypeConstants()
static constexpr bool IsNone(ECbFieldType Type)
static constexpr bool IsUuid(ECbFieldType Type)
static constexpr ECbFieldType ArrayBase
static constexpr bool IsBool(ECbFieldType Type)
static constexpr ECbFieldType GetSerializedType(ECbFieldType Type)
static constexpr bool IsBinaryAttachment(ECbFieldType Type)
static constexpr bool IsHash(ECbFieldType Type)
static constexpr ECbFieldType IntegerBase
static constexpr ECbFieldType FloatBase
static constexpr ECbFieldType BoolMask
static constexpr bool IsObject(ECbFieldType Type)
static constexpr ECbFieldType TypeMask
static constexpr bool HasFields(ECbFieldType Type)
static constexpr ECbFieldType FloatMask
static constexpr bool IsAttachment(ECbFieldType Type)
static constexpr bool MayContainAttachments(ECbFieldType Type)
static constexpr bool IsObjectAttachment(ECbFieldType Type)
static constexpr bool IsCustomByName(ECbFieldType Type)
static constexpr ECbFieldType ObjectBase
static constexpr ECbFieldType SerializedTypeMask
static constexpr bool IsDateTime(ECbFieldType Type)
static constexpr bool IsFloat(ECbFieldType Type)
static constexpr bool HasFieldName(ECbFieldType Type)
static constexpr ECbFieldType AttachmentBase
static constexpr bool HasFieldType(ECbFieldType Type)
static constexpr ECbFieldType IntegerMask
static constexpr bool HasUniformFields(ECbFieldType Type)
static constexpr ECbFieldType BoolBase
static constexpr ECbFieldType ObjectMask
static constexpr bool IsInteger(ECbFieldType Type)
static constexpr ECbFieldType AttachmentMask
static constexpr bool IsBinary(ECbFieldType Type)
static constexpr bool IsCustomById(ECbFieldType Type)
static constexpr bool IsString(ECbFieldType Type)
static constexpr bool IsNull(ECbFieldType Type)
FCbFieldView(const void *Data, ECbFieldType Type=ECbFieldType::HasFieldType)
FCbFieldView operator[](FUtf8StringView Name) const
constexpr bool IsArray() const
bool Equals(const FCbFieldView &Other) const
constexpr FUtf8StringView GetName() const
uint64 AsUInt64(uint64 Default=0)
void CopyTo(FArchive &Ar) const
constexpr bool HasName() const
constexpr operator bool() const
constexpr bool HasError() const
FTimespan AsTimeSpan(FTimespan Default)
int64 AsInt64(int64 Default=0)
FIoHash AsBinaryAttachment(const FIoHash &Default=FIoHash())
uint8 AsUInt8(uint8 Default=0)
ECbFieldType TypeWithFlags
constexpr bool IsInteger() const
uint32 AsUInt32(uint32 Default=0)
FIoHash AsHash(const FIoHash &Default=FIoHash())
constexpr bool IsObjectId() const
void AppendHash(FIoHashBuilder &Builder) const
FMemoryView AsBinaryView(FMemoryView Default=FMemoryView())
int64 AsDateTimeTicks(int64 Default=0)
FUtf8StringView AsString(FUtf8StringView Default=FUtf8StringView())
constexpr bool IsFloat() const
IntType AsInteger(IntType Default)
constexpr FCbIteratorSentinel end() const
FCbObjectView AsObjectView()
int32 AsInt32(int32 Default=0)
uint16 AsUInt16(uint16 Default=0)
int64 AsTimeSpanTicks(int64 Default=0)
FIoHash AsObjectAttachment(const FIoHash &Default=FIoHash())
FCbArrayView AsArrayView()
float AsFloat(float Default=0.0f)
void Assign(const void *InData, const ECbFieldType InType)
void IterateAttachments(FCbFieldVisitor Visitor) const
int16 AsInt16(int16 Default=0)
FMemoryView GetValueView() const
FDateTime AsDateTime(FDateTime Default)
FCbCustomByName AsCustomByName(FCbCustomByName Default=FCbCustomByName())
constexpr bool HasValue() const
constexpr FCbFieldView RemoveName() const
int8 AsInt8(int8 Default=0)
constexpr bool IsUuid() const
constexpr ECbFieldType GetTypeWithFlags() const
double AsDouble(double Default=0.0)
FIoHash AsAttachment(const FIoHash &Default=FIoHash())
constexpr bool IsCustomByName() const
FCbValue GetValue() const
constexpr bool IsHash() const
FMemoryView AsCustom(uint64 Id, FMemoryView Default=FMemoryView())
constexpr bool IsTimeSpan() const
uint64 AsInteger(uint64 Default, UE::CompactBinary::Private::FIntegerParams Params)
FMemoryView GetView() const
constexpr bool IsDateTime() const
bool AsBool(bool bDefault=false)
constexpr bool IsObject() const
void CopyTo(FMutableMemoryView Buffer) const
FMemoryView AsCustom(FUtf8StringView Name, FMemoryView Default=FMemoryView())
constexpr bool IsAttachment() const
FGuid AsUuid(const FGuid &Default)
constexpr bool IsObjectAttachment() const
constexpr bool IsString() const
FCbCustomById AsCustomById(FCbCustomById Default=FCbCustomById())
const void * GetValueEnd() const
FCbFieldViewIterator CreateViewIterator() const
constexpr bool IsNull() const
constexpr bool IsCustomById() const
FCbObjectId AsObjectId(const FCbObjectId &Default=FCbObjectId())
bool TryGetView(FMemoryView &OutView) const
FCbFieldView(const FCbValue &Value)
constexpr ECbFieldError GetError() const
FCbFieldViewIterator begin() const
constexpr bool IsBool() const
FMemoryView GetViewNoType() const
uint64 GetValueSize() const
constexpr bool IsBinaryAttachment() const
constexpr const void * GetValueData() const
constexpr FCbFieldView()=default
constexpr bool IsBinary() const
constexpr ECbFieldType GetType() const
static FCbFieldViewIterator MakeRange(FMemoryView View, ECbFieldType Type=ECbFieldType::HasFieldType)
constexpr FCbFieldViewIterator()=default
static FCbFieldViewIterator MakeSingle(const FCbFieldView &Field)
FCbFieldViewIterator(const TCbFieldIterator< OtherFieldType > &It)
FCbField FindIgnoreCase(FUtf8StringView Name) const
FCompositeBuffer GetBuffer() const
FCbField operator[](FUtf8StringView Name) const
FCbField Find(FUtf8StringView Name) const
FCbField AsField() const &
const ByteArray & GetBytes() const
bool operator<(const FCbObjectId &B) const
bool operator!=(const FCbObjectId &B) const
constexpr FMemoryView GetView() const
FCbObjectId(const ByteArray &ObjectId)
operator const ByteArray &() const
static FCbObjectId NewObjectId()
friend uint32 GetTypeHash(const FCbObjectId &Id)
friend TStringBuilderBase< CharType > & operator<<(TStringBuilderBase< CharType > &Builder, const FCbObjectId &Id)
FCbObjectId(FMemoryView ObjectId)
bool operator==(const FCbObjectId &B) const
FCbFieldView FindView(FUtf8StringView Name) const
FCbFieldView AsFieldView() const
void CopyTo(FArchive &Ar) const
FCbFieldView FindViewIgnoreCase(FUtf8StringView Name) const
void CopyTo(FMutableMemoryView Buffer) const
void AppendHash(FIoHashBuilder &Builder) const
FCbFieldView operator[](FUtf8StringView Name) const
void IterateAttachments(FCbFieldVisitor Visitor) const
static FCbObjectView FromFieldNoCheck(const FCbFieldView &Field)
bool Equals(const FCbObjectView &Other) const
bool TryGetView(FMemoryView &OutView) const
FCbObjectView(const FCbFieldView &Field)
static Type Clone(const ViewType &Value)
static Type MakeView(const ViewType &Value, FSharedBuffer OuterBuffer=FSharedBuffer())
static Type MakeView(const void *const Data, FSharedBuffer OuterBuffer=FSharedBuffer())
static Type Clone(const void *const Data)
constexpr FCbIteratorSentinel end() const
FCbFieldIterator begin() const
TCbBuffer(FSharedBuffer ValueBuffer, ECbFieldType Type=ECbFieldType::HasFieldType)
FSharedBuffer GetOuterBuffer() &&
const ViewType & AsView() const
const FSharedBuffer & GetOuterBuffer() const &
FCbField operator[](FUtf8StringView Name) const
TCbBuffer(const ViewType &Value, TCbBuffer< OtherViewType > OuterBuffer)
TCbBuffer(const ViewType &Value, FSharedBuffer OuterBuffer)
FCbFieldIterator CreateIterator() const
TCbFieldIterator operator++(int)
static const void * GetFieldsEnd(const TCbFieldIterator< OtherFieldType > &It)
uint64 GetRangeSize() const
constexpr TCbFieldIterator(FieldType &&InField, const void *InFieldsEnd)
void CopyRangeTo(FMutableMemoryView Buffer) const
constexpr FCbIteratorSentinel end() const
bool TryGetRangeView(FMemoryView &OutView) const
constexpr bool operator==(const TCbFieldIterator< OtherFieldType > &Other) const
TCbFieldIterator & operator++()
constexpr FieldType & operator*()
constexpr TCbFieldIterator begin() const
constexpr TCbFieldIterator(FieldType InField)
constexpr bool operator!=(const FCbIteratorSentinel &) const
constexpr bool operator==(const FCbIteratorSentinel &) const
void CopyRangeTo(FArchive &Ar) const
constexpr FieldType * operator->()
constexpr bool operator!=(const TCbFieldIterator< OtherFieldType > &Other) const
constexpr bool Equals(const TCbFieldIterator< OtherFieldType > &Other) const
void AppendRangeHash(FIoHashBuilder &Builder) const
void IterateRangeAttachments(FCbFieldVisitor Visitor) const
constexpr TCbFieldIterator()=default
FIoHash GetRangeHash() const
static constexpr FIntegerParams MakeIntegerParams()
static FORCEINLINE int32 Memcmp(const void *Buf1, const void *Buf2, SIZE_T Count)
static FORCEINLINE void * Memcpy(void *Dest, const void *Src, SIZE_T Count)