Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
BufferReader.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Misc/AssertionMacros.h"
7#include "HAL/UnrealMemory.h"
8#include "Serialization/Archive.h"
9#include "Containers/UnrealString.h"
10
11/**
12* Similar to FMemoryReader, but able to internally
13* manage the memory for the buffer.
14*/
16{
17public:
18 /**
19 * Constructor
20 *
21 * @param Data Buffer to use as the source data to read from
22 * @param Size Size of Data
23 * @param bInFreeOnClose If true, Data will be FMemory::Free'd when this archive is closed
24 * @param bIsPersistent Uses this value for SetIsPersistent()
25 * @param bInSHAVerifyOnClose It true, an async SHA verification will be done on the Data buffer (bInFreeOnClose will be passed on to the async task)
26 */
27 FBufferReaderBase(void* Data, int64 Size, bool bInFreeOnClose, bool bIsPersistent = false)
28 : ReaderData(Data)
29 , ReaderPos(0)
30 , ReaderSize(Size)
31 , bFreeOnClose(bInFreeOnClose)
32 {
33 this->SetIsLoading(true);
34 this->SetIsPersistent(bIsPersistent);
35 }
36
37 // Abstract to force implementors to call Close() themselves, since it's a virtual function.
38 virtual ~FBufferReaderBase() = 0;
39
40 virtual bool Close() override
41 {
42 if (bFreeOnClose)
43 {
45 ReaderData = nullptr;
46 }
47 return !IsError();
48 }
49 void Serialize(void* Data, int64 Num) final
50 {
51 check(ReaderPos >= 0);
52 check(ReaderPos + Num <= ReaderSize);
54 ReaderPos += Num;
55 }
56 int64 Tell() final
57 {
58 return ReaderPos;
59 }
60 int64 TotalSize() final
61 {
62 return ReaderSize;
63 }
64 void Seek(int64 InPos) final
65 {
66 check(InPos >= 0);
67 check(InPos <= ReaderSize);
68 ReaderPos = InPos;
69 }
70 bool AtEnd() final
71 {
72 return ReaderPos >= ReaderSize;
73 }
74 /**
75 * Returns the name of the Archive. Useful for getting the name of the package a struct or object
76 * is in when a loading error occurs.
77 *
78 * This is overridden for the specific Archive Types
79 **/
80 virtual FString GetArchiveName() const { return TEXT("FBufferReaderBase"); }
81protected:
83 int64 ReaderPos;
86};
87
89{
90}
91
92/**
93 * Similar to FMemoryReader, but able to internally
94 * manage the memory for the buffer.
95 */
96class FBufferReader final : public FBufferReaderBase
97{
98public:
99 /**
100 * Constructor
101 *
102 * @param Data Buffer to use as the source data to read from
103 * @param Size Size of Data
104 * @param bInFreeOnClose If true, Data will be FMemory::Free'd when this archive is closed
105 * @param bIsPersistent Uses this value for SetIsPersistent()
106 * @param bInSHAVerifyOnClose It true, an async SHA verification will be done on the Data buffer (bInFreeOnClose will be passed on to the async task)
107 */
108 FBufferReader( void* Data, int64 Size, bool bInFreeOnClose, bool bIsPersistent = false )
109 : FBufferReaderBase(Data, Size, bInFreeOnClose, bIsPersistent)
110 {
111 }
112
113 virtual ~FBufferReader() override
114 {
115 Close();
116 }
117
118 virtual FString GetArchiveName() const { return TEXT("FBufferReader"); }
119};
#define check(expr)
#define TEXT(x)
Definition Platform.h:1108
void Serialize(void *Data, int64 Num) final
int64 TotalSize() final
void Seek(int64 InPos) final
virtual bool Close() override
bool AtEnd() final
FBufferReaderBase(void *Data, int64 Size, bool bInFreeOnClose, bool bIsPersistent=false)
virtual ~FBufferReaderBase()=0
virtual FString GetArchiveName() const
int64 Tell() final
virtual FString GetArchiveName() const
FBufferReader(void *Data, int64 Size, bool bInFreeOnClose, bool bIsPersistent=false)
virtual ~FBufferReader() override
virtual void SetIsPersistent(bool bInIsPersistent)
FORCEINLINE bool IsError() const
Definition Archive.h:337
virtual void SetIsLoading(bool bInIsLoading)
static void Free(void *Original)
static FORCEINLINE void * Memcpy(void *Dest, const void *Src, SIZE_T Count)