FCbWriter

A writer for compact binary object, arrays, and fields.

Choose your operating system:

Windows

macOS

Linux

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

Name Description

Public function

FCbWriter()

Public function

FCbWriter

(
    const FCbWriter&
)

Protected function

FCbWriter

(
    int64 InitialSize
)

Private flags that are public to work with ENUM_CLASS_FLAGS.

Destructors

Name Description

Public function

~FCbWriter()

Functions

Name Description

Public function

void

 

AddArray

(
    const FCbArrayView& Value
)

Public function

void

 

AddArray

(
    const FCbArray& Value
)

Public function

void

 

AddArray

(
    FUtf8StringView Name,
    const FCbArrayView& Value
)

Copy the value (not the name) of an existing array.

Public function

void

 

AddArray

(
    FUtf8StringView Name,
    const FCbArray& Value
)

Copy the value (not the name) of an existing array. Holds a reference if owned.

Public function

void

 

AddAttachment

(
    const FCbAttachment& Attachment
)

Public function

void

 

AddAttachment

(
    FUtf8StringView Name,
    const FCbAttachment& Attachment
)

Write a field referencing the attachment by its hash.

Public function

void

 

AddBinary

(
    FUtf8StringView Name,
    const void* Value,
    uint64 Size
)

Write a binary field by copying Size bytes from Value.

Public function

void

 

AddBinary

(
    FUtf8StringView Name,
    const FCompositeBuffer& Value
)

Public function

void

 

AddBinary

(
    FUtf8StringView Name,
    const FSharedBuffer& Value
)

Write a binary field by copying the buffer. Holds a reference if owned.

Public function

void

 

AddBinary

(
    FUtf8StringView Name,
    FMemoryView Value
)

Write a binary field by copying the view.

Public function

void

 

AddBinary

(
    const FCompositeBuffer& Value
)

Write a binary field by copying Size bytes from Value.

Public function

void

 

AddBinary

(
    const FSharedBuffer& Value
)

Public function

void

 

AddBinary

(
    const void* Value,
    uint64 Size
)

Public function

void

 

AddBinary

(
    FMemoryView Value
)

Public function

void

 

AddBinaryAttachment

(
    const FIoHash& Value
)

Public function

void

 

AddBinaryAttachment

(
    FUtf8StringView Name,
    const FIoHash& Value
)

Write a field referencing a binary attachment by its hash.

Public function

void

 

AddBool

(
    bool bValue
)

Public function

void

 

AddBool

(
    FUtf8StringView Name,
    bool bValue
)

Write a bool field.

Public function

void

 

AddCustom

(
    FUtf8StringView FieldName,
    FUtf8StringView TypeName,
    FMemoryView Value
)

Write a custom field with a string sub-type identifier.

Public function

void

 

AddCustom

(
    FUtf8StringView FieldName,
    uint64 TypeId,
    FMemoryView Value
)

Write a custom field with an integer sub-type identifier.

Public function

void

 

AddCustom

(
    uint64 TypeId,
    FMemoryView Value
)

Public function

void

 

AddCustom

(
    FUtf8StringView TypeName,
    FMemoryView Value
)

Public function

void

 

AddDateTime

(
    FUtf8StringView Name,
    FDateTime Value
)

Write a date/time field.

Public function

void

 

AddDateTime

(
    FDateTime Value
)

Write a date/time field.

Public function

void

 

AddDateTimeTicks

(
    int64 Ticks
)

Public function

void

 

AddDateTimeTicks

(
    FUtf8StringView Name,
    int64 Ticks
)

Write a date/time field with the specified count of 100ns ticks since the epoch.

Public function

void

 

AddField

(
    const FCbField& Value
)

Public function

void

 

AddField

(
    FUtf8StringView Name,
    const FCbField& Value
)

Copy the value (not the name) of an existing field. Holds a reference if owned.

Public function

void

 

AddField

(
    FUtf8StringView Name,
    const FCbFieldView& Value
)

Copy the value (not the name) of an existing field.

Public function

void

 

AddField

(
    const FCbFieldView& Value
)

Public function

void

 

AddFloat

(
    double Value
)

Public function

void

 

AddFloat

(
    float Value
)

Public function

void

 

AddFloat

(
    FUtf8StringView Name,
    float Value
)

Write a float field from a 32-bit float value.

Public function

void

 

AddFloat

(
    FUtf8StringView Name,
    double Value
)

Write a float field from a 64-bit float value.

Public function

void

 

AddHash

(
    const FIoHash& Value
)

Public function

void

 

AddHash

(
    FUtf8StringView Name,
    const FIoHash& Value
)

Write a hash field.

Public function

void

 

AddInteger

(
    int32 Value
)

Public function

void

 

AddInteger

(
    FUtf8StringView Name,
    uint32 Value
)

Write an integer field.

Public function

void

 

AddInteger

(
    FUtf8StringView Name,
    int64 Value
)

Write an integer field.

Public function

void

 

AddInteger

(
    FUtf8StringView Name,
    int32 Value
)

Write an integer field.

Public function

void

 

AddInteger

(
    uint64 Value
)

Public function

void

 

AddInteger

(
    uint32 Value
)

Public function

void

 

AddInteger

(
    FUtf8StringView Name,
    uint64 Value
)

Write an integer field.

Public function

void

 

AddInteger

(
    int64 Value
)

Public function

void

 

AddNull()

Public function

void

 

AddNull

(
    FUtf8StringView Name
)

Write a null field.

Public function

void

 

AddObject

(
    const FCbObjectView& Value
)

Public function

void

 

AddObject

(
    const FCbObject& Value
)

Public function

void

 

AddObject

(
    FUtf8StringView Name,
    const FCbObject& Value
)

Copy the value (not the name) of an existing object. Holds a reference if owned.

Public function

void

 

AddObject

(
    FUtf8StringView Name,
    const FCbObjectView& Value
)

Copy the value (not the name) of an existing object.

Public function

void

 

AddObjectAttachment

(
    FUtf8StringView Name,
    const FIoHash& Value
)

Write a field referencing an object attachment by its hash.

Public function

void

 

AddObjectAttachment

(
    const FIoHash& Value
)

Public function

void

 

AddObjectId

(
    const FCbObjectId& Value
)

Public function

void

 

AddObjectId

(
    FUtf8StringView Name,
    const FCbObjectId& Value
)

Write an ObjectId field.

Public function

void

 

AddString

(
    FUtf8StringView Name,
    FWideStringView Value
)

Write a string field by converting the UTF-16 value to UTF-8.

Public function

void

 

AddString

(
    FUtf8StringView Value
)

Public function

void

 

AddString

(
    FWideStringView Value
)

Public function

void

 

AddString

(
    FUtf8StringView Name,
    FUtf8StringView Value
)

Write a string field by copying the UTF-8 value.

Public function

void

 

AddTimeSpan

(
    FTimespan Value
)

Write a time span field.

Public function

void

 

AddTimeSpan

(
    FUtf8StringView Name,
    FTimespan Value
)

Write a time span field.

Public function

void

 

AddTimeSpanTicks

(
    int64 Ticks
)

Public function

void

 

AddTimeSpanTicks

(
    FUtf8StringView Name,
    int64 Ticks
)

Write a time span field with the specified count of 100ns ticks.

Public function

void

 

AddUuid

(
    FUtf8StringView Name,
    const FGuid& Value
)

Write a UUID field.

Public function

void

 

AddUuid

(
    const FGuid& Value
)

Public function

void

 

BeginArray

(
    FUtf8StringView Name
)

Begin a new array. Must have a matching call to EndArray.

Public function

void

 

BeginArray()

Public function

void

 

BeginObject()

Public function

void

 

BeginObject

(
    FUtf8StringView Name
)

Begin a new object. Must have a matching call to EndObject.

Public function

void

 

EndArray()

End an array after its fields have been written.

Public function

void

 

EndObject()

End an object after its fields have been written.

Public function Const

uint64

 

GetSaveSize()

The size of buffer (in bytes) required to serialize the fields that have been written.

Public function

void

 

Reset()

Empty the writer without releasing any allocated memory.

Public function Const

FCbFieldView...

 

Save

(
    FMutableMemoryView Buffer
)

Serialize the field(s) to memory.

Public function Const

FCbFieldIter...

 

Save()

Serialize the field(s) to an owned buffer and return it as an iterator.

Public function Const

void

 

Save

(
    FArchive& Ar
)

Serialize the field(s) to an archive.

Public function

FCbWriter &

 

SetName

(
    FUtf8StringView Name
)

Sets the name of the next field to be written.

Operators

Name Description

Public function

FCbWriter &

 

operator=

(
    const FCbWriter&
)

Enums

Name

Description

Public enum

EStateFlags

See Also