You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
While there may be data remaining in the buffer, there might not be enough to decode another transport packet. Thus it is not correct to only consider the remaining number of bytes in the buffer as a condition of continuing to process data. Fortunately there is a demain hint that is set when someone asks for more data than a stream reader can provide. This can be used to differentiate between data remaining in the buffer, and not being able to do anything more with it. #rb martin.ridgers, johan.berg #rm 5.0 #ushell-cherrypick of 18267675 by Martin.Ridgers #jira UE-134430, UE-135475 #preflight 619cf19cf70a9e92db3b69f7 [CL 18269671 by Johan Berg in ue5-main branch]
91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreTypes.h"
|
|
|
|
namespace UE {
|
|
namespace Trace {
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
class FStreamReader
|
|
{
|
|
public:
|
|
~FStreamReader();
|
|
template <typename Type>
|
|
Type const* GetPointer();
|
|
template <typename Type>
|
|
Type const* GetPointerUnchecked();
|
|
const uint8* GetPointer(uint32 Size);
|
|
const uint8* GetPointerUnchecked();
|
|
void Advance(uint32 Size);
|
|
bool IsEmpty() const;
|
|
int32 GetRemaining() const;
|
|
bool CanMeetDemand() const;
|
|
bool Backtrack(const uint8* To);
|
|
struct FMark* SaveMark() const;
|
|
void RestoreMark(struct FMark* Mark);
|
|
|
|
protected:
|
|
uint8* Buffer = nullptr;
|
|
uint32 DemandHint = 0;
|
|
uint32 Cursor = 0;
|
|
uint32 End = 0;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
template <typename Type>
|
|
Type const* FStreamReader::GetPointer()
|
|
{
|
|
return (Type const*)GetPointer(sizeof(Type));
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
template <typename Type>
|
|
Type const* FStreamReader::GetPointerUnchecked()
|
|
{
|
|
return (Type const*)GetPointerUnchecked();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
inline const uint8* FStreamReader::GetPointerUnchecked()
|
|
{
|
|
return Buffer + Cursor;
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
class FStreamBuffer
|
|
: public FStreamReader
|
|
{
|
|
public:
|
|
template <typename Lambda>
|
|
int32 Fill(Lambda&& Source);
|
|
void Append(const uint8* Data, uint32 Size);
|
|
uint8* Append(uint32 Size);
|
|
|
|
protected:
|
|
void Consolidate();
|
|
uint32 BufferSize = 0;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
template <typename Lambda>
|
|
inline int32 FStreamBuffer::Fill(Lambda&& Source)
|
|
{
|
|
Consolidate();
|
|
|
|
uint8* Dest = Buffer + End;
|
|
int32 ReadSize = Source(Dest, BufferSize - End);
|
|
if (ReadSize > 0)
|
|
{
|
|
End += ReadSize;
|
|
}
|
|
|
|
return ReadSize;
|
|
}
|
|
|
|
} // namespace Trace
|
|
} // namespace UE
|