BsFileSerializer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Serialization
  6. * @{
  7. */
  8. // TODO - Low priority. Eventually I'll want to generalize BinarySerializer to Serializer class, then I can make this class accept
  9. // a generic Serializer interface so it may write both binary, plain-text or some other form of data.
  10. /** Encodes the provided object to the specified file using the RTTI system. */
  11. class BS_UTILITY_EXPORT FileEncoder
  12. {
  13. public:
  14. FileEncoder(const Path& fileLocation);
  15. ~FileEncoder();
  16. /**
  17. * Parses the provided object, serializes all of its data as specified by its RTTIType and saves the serialized
  18. * data to the provided file location.
  19. */
  20. void encode(IReflectable* object);
  21. private:
  22. /** Called by the binary serializer whenever the buffer gets full. */
  23. UINT8* flushBuffer(UINT8* bufferStart, UINT32 bytesWritten, UINT32& newBufferSize);
  24. std::ofstream mOutputStream;
  25. UINT8* mWriteBuffer;
  26. static const UINT32 WRITE_BUFFER_SIZE = 2048;
  27. };
  28. /** Decodes objects from the specified file using the RTTI system. */
  29. class BS_UTILITY_EXPORT FileDecoder
  30. {
  31. public:
  32. FileDecoder(const Path& fileLocation);
  33. ~FileDecoder();
  34. /** Deserializes an IReflectable object by reading the binary data at the provided file location. */
  35. std::shared_ptr<IReflectable> decode();
  36. /** Skips over than object in the file. Calling decode() will decode the next object. */
  37. void skip();
  38. private:
  39. std::ifstream mInputStream;
  40. };
  41. /** @} */
  42. }