Serializer.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Util/Serializer.h>
  6. namespace anki {
  7. Error BinarySerializer::doDynamicArrayBasicType(const void* arr, PtrSize size, U32 alignment, PtrSize memberOffset)
  8. {
  9. check();
  10. if(size == 0)
  11. {
  12. ANKI_ASSERT(arr == nullptr);
  13. // Do nothing
  14. }
  15. else
  16. {
  17. ANKI_ASSERT(arr);
  18. // Move file pos to the end of the file (allocate space)
  19. PtrSize arrayFilePos = getAlignedRoundUp(alignment, m_eofPos);
  20. m_eofPos = arrayFilePos + size;
  21. // Store the pointer for later
  22. const PtrSize structFilePos = m_structureFilePos.getBack();
  23. PointerInfo pinfo;
  24. pinfo.m_filePos = structFilePos + memberOffset;
  25. pinfo.m_value = arrayFilePos - m_beginOfDataFilePos;
  26. m_pointerFilePositions.emplaceBack(pinfo);
  27. // Write the array
  28. ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::kBeginning));
  29. ANKI_CHECK(m_file->write(arr, size));
  30. }
  31. check();
  32. return Error::kNone;
  33. }
  34. } // end namespace anki