Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FCbPackage Class Reference

#include <CompactBinaryPackage.h>

+ Collaboration diagram for FCbPackage:

Public Types

using FAttachmentResolver = TFunctionRef<FSharedBuffer (const FIoHash& Hash)>
 

Public Member Functions

 FCbPackage ()=default
 
 FCbPackage (FCbObject InObject)
 
 FCbPackage (FCbObject InObject, FAttachmentResolver InResolver)
 
 FCbPackage (FCbObject InObject, const FIoHash &InObjectHash)
 
 FCbPackage (FCbObject InObject, const FIoHash &InObjectHash, FAttachmentResolver InResolver)
 
void Reset ()
 
 operator bool () const
 
bool IsNull () const
 
const FCbObjectGetObject () const
 
const FIoHashGetObjectHash () const
 
void SetObject (FCbObject InObject)
 
void SetObject (FCbObject InObject, FAttachmentResolver InResolver)
 
void SetObject (FCbObject InObject, const FIoHash &InObjectHash)
 
void SetObject (FCbObject InObject, const FIoHash &InObjectHash, FAttachmentResolver InResolver)
 
TConstArrayView< FCbAttachmentGetAttachments () const
 
const FCbAttachmentFindAttachment (const FIoHash &Hash) const
 
const FCbAttachmentFindAttachment (const FCbAttachment &Attachment) const
 
void AddAttachment (const FCbAttachment &Attachment)
 
void AddAttachment (const FCbAttachment &Attachment, FAttachmentResolver Resolver)
 
int32 RemoveAttachment (const FIoHash &Hash)
 
int32 RemoveAttachment (const FCbAttachment &Attachment)
 
bool Equals (const FCbPackage &Package) const
 
bool operator== (const FCbPackage &Package) const
 
bool operator!= (const FCbPackage &Package) const
 
bool TryLoad (FCbFieldIterator &Fields)
 
bool TryLoad (FArchive &Ar, FCbBufferAllocator Allocator=FUniqueBuffer::Alloc)
 
void Save (FCbWriter &Writer) const
 
void Save (FArchive &Ar) const
 

Private Member Functions

void SetObject (FCbObject Object, const FIoHash *Hash, FAttachmentResolver *Resolver)
 
void AddAttachment (const FCbAttachment &Attachment, FAttachmentResolver *Resolver)
 
void GatherAttachments (const FCbObject &Object, FAttachmentResolver Resolver)
 

Private Attributes

TArray< FCbAttachmentAttachments
 
FCbObject Object
 
FIoHash ObjectHash
 

Detailed Description

A package is an object with a tree of referenced attachments.

A package is a Merkle tree with an object as its root and non-leaf nodes, and either binary or objects as its leaf nodes. Nodes reference their children from fields of type BinaryAttachment or ObjectAttachment, which store the raw hash of the referenced attachment.

It is invalid for a package to include attachments that are not referenced by its object or by one of its referenced object attachments. This invariant needs to be maintained if attachments are added explicitly instead of being discovered by the attachment resolver. If any attachment is not referenced, it may not survive a round-trip through certain storage systems.

It is valid for a package to exclude referenced attachments, but then it is the responsibility of the package consumer to have a mechanism for resolving those references when necessary.

A package is serialized as a sequence of compact binary fields with no name. The object may be both preceded and followed by attachments. The object is only serialized when it is non-empty, starting with its hash, in a Hash field, followed by the object, in an Object field. A package ends with a Null field. The canonical order of components is the object and its hash, followed by the attachments ordered by hash, followed by a Null field. It is valid for the a package to have its attachments serialized in any order relative to each other and to the object.

Definition at line 218 of file CompactBinaryPackage.h.

Member Typedef Documentation

◆ FAttachmentResolver

A function that resolves a hash to a buffer containing the data matching that hash.

The resolver may return a null buffer to skip resolving an attachment for the hash.

Definition at line 226 of file CompactBinaryPackage.h.

Constructor & Destructor Documentation

◆ FCbPackage() [1/5]

FCbPackage::FCbPackage ( )
default

Construct a null package.

+ Here is the caller graph for this function:

◆ FCbPackage() [2/5]

FCbPackage::FCbPackage ( FCbObject InObject)
inlineexplicit

Construct a package from a root object without gathering attachments.

Parameters
InObjectThe root object, which will be cloned unless it is owned.

Definition at line 236 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:

◆ FCbPackage() [3/5]

FCbPackage::FCbPackage ( FCbObject InObject,
FAttachmentResolver InResolver )
inlineexplicit

Construct a package from a root object and gather attachments using the resolver.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InResolverA function that is invoked for every reference and binary reference field.

Definition at line 247 of file CompactBinaryPackage.h.

◆ FCbPackage() [4/5]

FCbPackage::FCbPackage ( FCbObject InObject,
const FIoHash & InObjectHash )
inlineexplicit

Construct a package from a root object without gathering attachments.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InObjectHashThe hash of the object, which must match to avoid validation errors.

Definition at line 258 of file CompactBinaryPackage.h.

◆ FCbPackage() [5/5]

FCbPackage::FCbPackage ( FCbObject InObject,
const FIoHash & InObjectHash,
FAttachmentResolver InResolver )
inlineexplicit

Construct a package from a root object and gather attachments using the resolver.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InObjectHashThe hash of the object, which must match to avoid validation errors.
InResolverA function that is invoked for every reference and binary reference field.

Definition at line 270 of file CompactBinaryPackage.h.

Member Function Documentation

◆ AddAttachment() [1/3]

void FCbPackage::AddAttachment ( const FCbAttachment & Attachment)
inline

Add the attachment to this package.

Definition at line 352 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddAttachment() [2/3]

void FCbPackage::AddAttachment ( const FCbAttachment & Attachment,
FAttachmentResolver * Resolver )
private

◆ AddAttachment() [3/3]

void FCbPackage::AddAttachment ( const FCbAttachment & Attachment,
FAttachmentResolver Resolver )
inline

Add the attachment to this package, along with any references that can be resolved.

Definition at line 358 of file CompactBinaryPackage.h.

◆ Equals()

bool FCbPackage::Equals ( const FCbPackage & Package) const

Compares packages by their object and attachment hashes.

+ Here is the caller graph for this function:

◆ FindAttachment() [1/2]

const FCbAttachment * FCbPackage::FindAttachment ( const FCbAttachment & Attachment) const
inline

Find an attachment if it exists in the package.

Definition at line 346 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindAttachment() [2/2]

const FCbAttachment * FCbPackage::FindAttachment ( const FIoHash & Hash) const

Find an attachment by its hash.

Returns
The attachment, or null if the attachment is not found.
Note
The returned pointer is only valid until the attachments on this package are modified.

◆ GatherAttachments()

void FCbPackage::GatherAttachments ( const FCbObject & Object,
FAttachmentResolver Resolver )
private

◆ GetAttachments()

TConstArrayView< FCbAttachment > FCbPackage::GetAttachments ( ) const
inline

Returns the attachments in this package.

Definition at line 335 of file CompactBinaryPackage.h.

◆ GetObject()

const FCbObject & FCbPackage::GetObject ( ) const
inline

Returns the object for the package.

Definition at line 285 of file CompactBinaryPackage.h.

◆ GetObjectHash()

const FIoHash & FCbPackage::GetObjectHash ( ) const
inline

Returns the hash of the object for the package.

Definition at line 288 of file CompactBinaryPackage.h.

◆ IsNull()

bool FCbPackage::IsNull ( ) const
inline

Whether the package has an empty object and no attachments.

Definition at line 282 of file CompactBinaryPackage.h.

+ Here is the caller graph for this function:

◆ operator bool()

FCbPackage::operator bool ( ) const
inlineexplicit

Whether the package has a non-empty object or attachments.

Definition at line 279 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:

◆ operator!=()

bool FCbPackage::operator!= ( const FCbPackage & Package) const
inline

Definition at line 374 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:

◆ operator==()

bool FCbPackage::operator== ( const FCbPackage & Package) const
inline

Definition at line 373 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:

◆ RemoveAttachment() [1/2]

int32 FCbPackage::RemoveAttachment ( const FCbAttachment & Attachment)
inline

Definition at line 369 of file CompactBinaryPackage.h.

◆ RemoveAttachment() [2/2]

int32 FCbPackage::RemoveAttachment ( const FIoHash & Hash)

Remove an attachment by hash.

Returns
Number of attachments removed, which will be either 0 or 1.

◆ Reset()

void FCbPackage::Reset ( )
inline

Reset this to a null package.

Definition at line 276 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:

◆ Save() [1/2]

void FCbPackage::Save ( FArchive & Ar) const

Save the object and attachments into the archive as a stream of compact binary fields.

◆ Save() [2/2]

void FCbPackage::Save ( FCbWriter & Writer) const

Save the object and attachments into the writer as a stream of compact binary fields.

◆ SetObject() [1/5]

void FCbPackage::SetObject ( FCbObject InObject)
inline

Set the root object without gathering attachments.

Parameters
InObjectThe root object, which will be cloned unless it is owned.

Definition at line 295 of file CompactBinaryPackage.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetObject() [2/5]

void FCbPackage::SetObject ( FCbObject InObject,
const FIoHash & InObjectHash )
inline

Set the root object without gathering attachments.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InObjectHashThe hash of the object, which must match to avoid validation errors.

Definition at line 317 of file CompactBinaryPackage.h.

◆ SetObject() [3/5]

void FCbPackage::SetObject ( FCbObject InObject,
const FIoHash & InObjectHash,
FAttachmentResolver InResolver )
inline

Set the root object and gather attachments using the resolver.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InObjectHashThe hash of the object, which must match to avoid validation errors.
InResolverA function that is invoked for every reference and binary reference field.

Definition at line 329 of file CompactBinaryPackage.h.

◆ SetObject() [4/5]

void FCbPackage::SetObject ( FCbObject InObject,
FAttachmentResolver InResolver )
inline

Set the root object and gather attachments using the resolver.

Parameters
InObjectThe root object, which will be cloned unless it is owned.
InResolverA function that is invoked for every reference and binary reference field.

Definition at line 306 of file CompactBinaryPackage.h.

◆ SetObject() [5/5]

void FCbPackage::SetObject ( FCbObject Object,
const FIoHash * Hash,
FAttachmentResolver * Resolver )
private

◆ TryLoad() [1/2]

bool FCbPackage::TryLoad ( FArchive & Ar,
FCbBufferAllocator Allocator = FUniqueBuffer::Alloc )

Load the object and attachments from compact binary as written by Save.

The object and attachments will be individually loaded into owned buffers.

Parameters
ArArchive to read the package from. An error state is set on failure.
AllocatorAllocator for object and attachment buffers.
Note
Allocated buffers will be cloned if they are not owned.

◆ TryLoad() [2/2]

bool FCbPackage::TryLoad ( FCbFieldIterator & Fields)

Load the object and attachments from compact binary as written by Save.

The object and attachments reference the input iterator, if it is owned, and otherwise clones the object and attachments individually to make owned copies.

The iterator is advanced as object and attachment fields are consumed from it.

Member Data Documentation

◆ Attachments

TArray<FCbAttachment> FCbPackage::Attachments
private

Attachments ordered by their hash.

Definition at line 410 of file CompactBinaryPackage.h.

◆ Object

FCbObject FCbPackage::Object
private

Definition at line 411 of file CompactBinaryPackage.h.

◆ ObjectHash

FIoHash FCbPackage::ObjectHash
private

Definition at line 412 of file CompactBinaryPackage.h.


The documentation for this class was generated from the following file: