Plasma Engine  2.0
Loading...
Searching...
No Matches
ChunkStream.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Containers/Deque.h>
5#include <Foundation/IO/Stream.h>
6
11class PL_FOUNDATION_DLL plChunkStreamWriter : public plStreamWriter
12{
13public:
15 plChunkStreamWriter(plStreamWriter& inout_stream); // [tested]
16
18 virtual plResult WriteBytes(const void* pWriteBuffer, plUInt64 uiBytesToWrite) override; // [tested]
19
22 virtual void BeginStream(plUInt16 uiVersion); // [tested]
23
25 virtual void EndStream(); // [tested]
26
28 virtual void BeginChunk(plStringView sName, plUInt32 uiVersion); // [tested]
29
31 virtual void EndChunk(); // [tested]
32
33
34private:
35 bool m_bWritingFile;
36 bool m_bWritingChunk;
37 plString m_sChunkName;
38 plDeque<plUInt8> m_Storage;
39 plStreamWriter& m_Stream;
40};
41
42
46class PL_FOUNDATION_DLL plChunkStreamReader : public plStreamReader
47{
48public:
50 plChunkStreamReader(plStreamReader& inout_stream); // [tested]
51
54 virtual plUInt64 ReadBytes(void* pReadBuffer, plUInt64 uiBytesToRead) override; // [tested]
55
57 {
58 SkipToEnd,
60 JustClose
62 };
63
64 void SetEndChunkFileMode(EndChunkFileMode mode) { m_EndChunkFileMode = mode; } // [tested]
65
67 virtual plUInt16 BeginStream(); // [tested]
68
71 virtual void EndStream(); // [tested]
72
74 struct ChunkInfo
75 {
76 ChunkInfo()
77 {
78 m_bValid = false;
79 m_uiChunkVersion = 0;
80 m_uiChunkBytes = 0;
81 m_uiUnreadChunkBytes = 0;
82 }
83
84 bool m_bValid;
87 plUInt32 m_uiChunkBytes;
89 };
90
92 const ChunkInfo& GetCurrentChunk() const { return m_ChunkInfo; } // [tested]
93
95 void NextChunk(); // [tested]
96
97private:
98 void TryReadChunkHeader();
99
100 EndChunkFileMode m_EndChunkFileMode;
101 ChunkInfo m_ChunkInfo;
102
103 plStreamReader& m_Stream;
104};
Reader for the chunk format that plChunkStreamWriter writes.
Definition ChunkStream.h:47
EndChunkFileMode
Definition ChunkStream.h:57
const ChunkInfo & GetCurrentChunk() const
Returns information about the current chunk.
Definition ChunkStream.h:92
A stream writer that separates data into 'chunks', which act like sub-streams.
Definition ChunkStream.h:12
Definition Deque.h:270
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
virtual plResult WriteBytes(const void *pWriteBuffer, plUInt64 uiBytesToWrite)=0
Writes a raw number of bytes from the buffer, this is the only method which has to be implemented to ...
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Describes the state of the current chunk.
Definition ChunkStream.h:75
plUInt32 m_uiUnreadChunkBytes
The number of bytes in the chunk that have not yet been read.
Definition ChunkStream.h:88
plUInt32 m_uiChunkVersion
The version number of the chunk.
Definition ChunkStream.h:86
plUInt32 m_uiChunkBytes
The total size of the chunk.
Definition ChunkStream.h:87
bool m_bValid
If this is false, the end of the chunk file has been reached and no further chunk is available.
Definition ChunkStream.h:84
plString m_sChunkName
The name of the chunk.
Definition ChunkStream.h:85
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54