AuroraRuntime/Include/Aurora/IO/Protocol/ProtocolStackFromDescription.hpp

85 lines
3.0 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ProtocolStackFromDescription.cpp
Date: 2023-09-21
Author: Reece
***/
#pragma once
namespace Aurora::IO::Protocol
{
struct ProtocolStackByBuffered
{
AuUInt uBufferedStreamLength { 128 * 1024 };
};
struct ProtocolStackByBufferedAdhoc : ProtocolStackByBuffered
{
AuSPtr<IStreamReader> pStreamReader {};
AuUInt uPreferredFragmentSize {};
};
struct ProtocolStackByPipe
{
AuSPtr<IIOPipeWork> pWork;
bool bAutoTick = true;
bool bKillPipeOnFirstRootLevelFalse = true;
};
struct ProtocolStackExtraData
{
AuOptionalEx<bool> bKillPipeOnFirstRootLevelFalse {};
bool bStreamReaderFlagAdhocPump {};
bool bStreamReaderFlagAdhocReadFromAdhoc {};
bool bFeatPending {};
};
AUE_DEFINE_VA(EProtocolStackCreateType,
eByPipe,
eByBuffered,
eByBufferedAdhocStream
);
struct ProtocolStackDescription
{
inline ProtocolStackDescription(AuUInt uBufferedStreamLength = 128 * 1024) :
type(EProtocolStackCreateType::eByBuffered),
byBuffered({ uBufferedStreamLength })
{
}
inline ProtocolStackDescription(const AuSPtr<IIOPipeWork> &pWork,
bool bAutoTick = true,
bool bKillPipeOnFirstRootLevelFalse = true) :
type(EProtocolStackCreateType::eByPipe),
byPipe({ pWork, bAutoTick, bKillPipeOnFirstRootLevelFalse })
{
}
inline ProtocolStackDescription(AuSPtr<IStreamReader> pStreamReader,
AuUInt uPreferredFragmentSize = 0,
AuUInt uBufferedStreamLength = 128 * 1024) :
type(EProtocolStackCreateType::eByBufferedAdhocStream),
byBufferedStream({ uBufferedStreamLength, pStreamReader, uPreferredFragmentSize })
{
}
EProtocolStackCreateType type;
ProtocolStackByPipe byPipe;
ProtocolStackByBuffered byBuffered;
ProtocolStackByBufferedAdhoc byBufferedStream;
ProtocolStackExtraData extendedFlags;
};
AUKN_SYM AuSPtr<IProtocolStack> NewProtocolStackFromDescription(const ProtocolStackDescription &description);
AUKN_SYM AuSPtr<IStreamReader> UtilityWrapStreamReaderWithInterceptors(AuSPtr<IStreamReader> pStreamReader,
AuList<AuTuple<bool /* bSingleFrame*/, AuUInt /*nextBufferSize*/, AuSPtr<IProtocolInterceptorEx>>> pairs,
AuUInt uBaseStreamLength = 128 * 1024,
AuUInt uPreferredFragmentSize = 0,
AuSPtr<IProtocolStack> *pOptOutStack = nullptr);
}