BsFileSerializer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 the provided object to the specified file using the RTTI system.
  9. */
  10. class BS_UTILITY_EXPORT FileEncoder
  11. {
  12. public:
  13. FileEncoder(const Path& fileLocation);
  14. ~FileEncoder();
  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);
  20. private:
  21. /**
  22. * @brief Called by the binary serializer whenever the buffer gets full.
  23. */
  24. UINT8* flushBuffer(UINT8* bufferStart, int bytesWritten, UINT32& newBufferSize);
  25. std::ofstream mOutputStream;
  26. UINT8* mWriteBuffer;
  27. static const UINT32 WRITE_BUFFER_SIZE = 2048;
  28. };
  29. /**
  30. * @brief Decodes objects from the specified file using the RTTI system.
  31. */
  32. class BS_UTILITY_EXPORT FileDecoder
  33. {
  34. public:
  35. FileDecoder(const Path& fileLocation);
  36. ~FileDecoder();
  37. /**
  38. * @brief Deserializes an IReflectable object by reading the binary data at
  39. * the provided file location.
  40. */
  41. std::shared_ptr<IReflectable> decode();
  42. /**
  43. * @brief Skips over than object in the file. Calling "decode" will decode
  44. * the next object.
  45. */
  46. void skip();
  47. private:
  48. std::ifstream mInputStream;
  49. };
  50. }