ChunkedDataBuffer.h 959 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include "../Common.h"
  3. NS_BF_BEGIN;
  4. class DataStream;
  5. class ChunkedDataBuffer
  6. {
  7. public:
  8. static const int ALLOC_SIZE = 0x1000;
  9. public:
  10. Array<uint8*> mPools;
  11. uint8* mWriteCurAlloc;
  12. uint8* mWriteCurPtr;
  13. uint8* mReadCurAlloc;
  14. uint8* mReadCurPtr;
  15. uint8* mReadNextAlloc;
  16. int mReadPoolIdx;
  17. int mSize;
  18. static int sBlocksAllocated;
  19. public:
  20. ChunkedDataBuffer();
  21. ~ChunkedDataBuffer();
  22. void InitFlatRef(void* ptr, int size);
  23. void Clear();
  24. int GetSize();
  25. void GrowPool();
  26. void Write(const void* data, int size);
  27. void Write(uint8 byte);
  28. void Write_2(uint16 val);
  29. void Write_3(uint32 val);
  30. void Write_4(uint32 val);
  31. int GetReadPos();
  32. void SetReadPos(int pos);
  33. void NextReadPool();
  34. void Read(void* data, int size);
  35. void* FastRead(void* data, int size); // Can either return pointer into the stream or read data, depending on if the read crosses a chunk
  36. uint8 Read();
  37. void Read(DataStream& stream, int size);
  38. };
  39. NS_BF_END;