BsFileSerializer.h 1.7 KB

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