Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/Serialization
Inheritance Hierarchy
- FCbWriter
- TCbWriter
References
| Module | Core |
| Header | /Engine/Source/Runtime/Core/Public/Serialization/CompactBinaryWriter.h |
| Include | #include "Serialization/CompactBinaryWriter.h" |
Syntax
class FCbWriter
Remarks
A writer for compact binary object, arrays, and fields.
The writer produces a sequence of fields that can be saved to a provided memory buffer or into a new owned buffer. The typical use case is to write a single object, which can be accessed by calling Save().AsObject() or Save(Buffer).AsObjectView().
The writer will assert on most incorrect usage and will always produce valid compact binary if provided with valid input. The writer does not check for invalid UTF-8 string encoding, object fields with duplicate names, or invalid compact binary being copied from another source.
It is most convenient to use the streaming API for the writer, as demonstrated in the example.
When writing a small amount of compact binary data, TCbWriter can be more efficient as it uses a fixed-size stack buffer for storage before spilling onto the heap.
Example:
FCbObject WriteObject() { TCbWriter<256> Writer; Writer.BeginObject();
Writer << "Resize" << true; Writer << "MaxWidth" << 1024; Writer << "MaxHeight" << 1024;
Writer.BeginArray(); Writer << "FormatA" << "FormatB" << "FormatC"; Writer.EndArray();
Writer.EndObject(); return Writer.Save().AsObject(); }
Constructors
| Type | Name | Description | |
|---|---|---|---|
FCbWriter () |
|||
| Reserve the specified size up front until the format is optimized. |
Destructors
| Type | Name | Description | |
|---|---|---|---|
~FCbWriter () |
Functions
| Type | Name | Description | |
|---|---|---|---|
| void | AddArray
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing array. Holds a reference if owned. | |
| void | AddArray
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing array. | |
| void | AddArray
(
const FCbArrayView& Value |
||
| void | |||
| void | AddAttachment
(
const FCbAttachment& Attachment |
||
| void | AddAttachment
(
FUtf8StringView Name, |
Write a field referencing the attachment by its hash. | |
| void | AddBinary
(
FUtf8StringView Name, |
||
| void | AddBinary
(
FUtf8StringView Name, |
Write a binary field by copying the buffer. Holds a reference if owned. | |
| void | |||
| void | AddBinary
(
FMemoryView Value |
||
| void | AddBinary
(
const FSharedBuffer& Value |
||
| void | AddBinary
(
const FCompositeBuffer& Value |
||
| void | AddBinary
(
FUtf8StringView Name, |
Write a binary field by copying Size bytes from Value. | |
| void | AddBinary
(
FUtf8StringView Name, |
Write a binary field by copying the view. | |
| void | AddBinaryAttachment
(
const FIoHash& Value |
||
| void | AddBinaryAttachment
(
FUtf8StringView Name, |
Write a field referencing a binary attachment by its hash. | |
| void | AddBool
(
bool bValue |
||
| void | AddBool
(
FUtf8StringView Name, |
Write a bool field. | |
| void | AddCustom
(
uint64 TypeId, |
||
| void | AddCustom
(
FUtf8StringView TypeName, |
||
| void | AddCustom
(
FUtf8StringView FieldName, |
Write a custom field with an integer sub-type identifier. | |
| void | AddCustom
(
FUtf8StringView FieldName, |
Write a custom field with a string sub-type identifier. | |
| void | AddDateTime
(
FUtf8StringView Name, |
Write a date/time field. | |
| void | AddDateTime
(
FDateTime Value |
||
| void | AddDateTimeTicks
(
FUtf8StringView Name, |
Write a date/time field with the specified count of 100ns ticks since the epoch. | |
| void | AddDateTimeTicks
(
int64 Ticks |
||
| void | AddField
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing field. Holds a reference if owned. | |
| void | AddField
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing field. | |
| void | AddField
(
const FCbFieldView& Value |
||
| void | |||
| void | AddFloat
(
float Value |
||
| void | AddFloat
(
double Value |
||
| void | AddFloat
(
FUtf8StringView Name, |
Write a float field from a 32-bit float value. | |
| void | AddFloat
(
FUtf8StringView Name, |
Write a float field from a 64-bit float value. | |
| void | AddHash
(
FUtf8StringView Name, |
Write a hash field. | |
| void | |||
| void | AddInteger
(
int32 Value |
||
| void | AddInteger
(
int64 Value |
||
| void | AddInteger
(
uint32 Value |
||
| void | AddInteger
(
uint64 Value |
||
| void | AddInteger
(
FUtf8StringView Name, |
Write an integer field. | |
| void | AddInteger
(
FUtf8StringView Name, |
Write an integer field. | |
| void | AddInteger
(
FUtf8StringView Name, |
Write an integer field. | |
| void | AddInteger
(
FUtf8StringView Name, |
Write an integer field. | |
| void | AddNull
(
FUtf8StringView Name |
Write a null field. | |
| void | AddNull () |
||
| void | AddObject
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing object. Holds a reference if owned. | |
| void | |||
| void | AddObject
(
const FCbObjectView& Value |
||
| void | AddObject
(
FUtf8StringView Name, |
Copy the value (not the name) of an existing object. | |
| void | AddObjectAttachment
(
const FIoHash& Value |
||
| void | AddObjectAttachment
(
FUtf8StringView Name, |
Write a field referencing an object attachment by its hash. | |
| void | AddObjectId
(
const FCbObjectId& Value |
||
| void | AddObjectId
(
FUtf8StringView Name, |
Write an ObjectId field. | |
| void | AddString
(
FUtf8StringView Name, |
Write a string field by converting the UTF-16 value to UTF-8. | |
| void | AddString
(
FUtf8StringView Value |
||
| void | AddString
(
FWideStringView Value |
||
| void | AddString
(
FUtf8StringView Name, |
Write a string field by copying the UTF-8 value. | |
| void | AddTimeSpan
(
FTimespan Value |
||
| void | AddTimeSpan
(
FUtf8StringView Name, |
Write a time span field. | |
| void | AddTimeSpanTicks
(
FUtf8StringView Name, |
Write a time span field with the specified count of 100ns ticks. | |
| void | AddTimeSpanTicks
(
int64 Ticks |
||
| void | |||
| void | AddUuid
(
FUtf8StringView Name, |
Write a UUID field. | |
| void | BeginArray () |
||
| void | BeginArray
(
FUtf8StringView Name |
Begin a new array. Must have a matching call to EndArray. | |
| void | BeginObject () |
||
| void | BeginObject
(
FUtf8StringView Name |
Begin a new object. Must have a matching call to EndObject. | |
| void | EndArray () |
End an array after its fields have been written. | |
| void | EndObject () |
End an object after its fields have been written. | |
| uint64 | GetSaveSize () |
The size of buffer (in bytes) required to serialize the fields that have been written. | |
| void | Reset () |
Empty the writer without releasing any allocated memory. | |
| FCbFieldViewIterator | Save
(
FMutableMemoryView Buffer |
Serialize the field(s) to memory. | |
| FCbFieldIterator | Save () |
Serialize the field(s) to an owned buffer and return it as an iterator. | |
| void | Serialize the field(s) to an archive. | ||
| FCbWriter & | SetName
(
FUtf8StringView Name |
Sets the name of the next field to be written. |
Operators
| Type | Name | Description | |
|---|---|---|---|
| FCbWriter & | operator<<
(
bool Value |
||
| FCbWriter & | operator<<
(
uint64 Value |
||
| FCbWriter & | operator<<
(
uint32 Value |
||
| FCbWriter & | operator<<
(
float Value |
||
| FCbWriter & | operator<<
(
double Value |
||
| FCbWriter & | operator<<
(
const FCbAttachment& Attachment |
||
| FCbWriter & | operator<<
(
const UTF8CHAR* NameOrValue |
Write the field name if valid in this state, otherwise write the string value. | |
| FCbWriter & | operator<<
(
const FGuid& Value |
||
| FCbWriter & | operator<<
(
FDateTime Value |
||
| FCbWriter & | operator<<
(
FTimespan Value |
||
| FCbWriter & | operator<<
(
int64 Value |
||
| FCbWriter & | operator<<
(
const FCbObjectId& Value |
||
| FCbWriter & | operator<<
(
const FString& Value |
||
| FCbWriter & | operator<<
(
const FIoHash& Value |
||
| FCbWriter & | operator<<
(
int32 Value |
||
| FCbWriter & | operator<<
(
FUtf8StringView NameOrValue |
Write the field name if valid in this state, otherwise write the string value. | |
| FCbWriter & | operator<<
(
FWideStringView Value |
||
| FCbWriter & | operator<<
(
nullptr_t |
||
| FCbWriter & | operator<<
(
const FCbArray& Value |
||
| FCbWriter & | operator<<
(
const FCbArrayView& Value |
||
| FCbWriter & | operator<<
(
const FCbObject& Value |
||
| FCbWriter & | operator<<
(
const FCbObjectView& Value |
||
| FCbWriter & | operator<<
(
const FCbField& Value |
||
| FCbWriter & | operator<<
(
const FCbFieldView& Value |
||
| FCbWriter & | operator<<
(
FName Value |
||
| FCbWriter & | operator<<
(
const ANSICHAR* NameOrValue |
Write the field name if valid in this state, otherwise write the string value. | |
| FCbWriter & | operator<<
(
const FAnsiString& Value |
||
| FCbWriter & | operator<<
(
const TArray< T, Allocator >& Value |
||
| FCbWriter & | operator<<
(
const WIDECHAR* Value |
||
| FCbWriter & | operator<<
(
const FUtf8String& Value |
||
| FCbWriter & |
Enums
| Type | Name | Description | |
|---|---|---|---|
| EStateFlags |