BsFileSerializer.h 1.4 KB

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