Serializer.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (C) 2009-2021, 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. {
  8. Error BinarySerializer::doDynamicArrayBasicType(const void* arr, PtrSize size, U32 alignment, PtrSize memberOffset)
  9. {
  10. check();
  11. if(size == 0)
  12. {
  13. ANKI_ASSERT(arr == nullptr);
  14. // Do nothing
  15. }
  16. else
  17. {
  18. ANKI_ASSERT(arr);
  19. // Move file pos to the end of the file (allocate space)
  20. PtrSize arrayFilePos = getAlignedRoundUp(alignment, m_eofPos);
  21. m_eofPos = arrayFilePos + size;
  22. // Store the pointer for later
  23. const PtrSize structFilePos = m_structureFilePos.getBack();
  24. PointerInfo pinfo;
  25. pinfo.m_filePos = structFilePos + memberOffset;
  26. pinfo.m_value = arrayFilePos - m_beginOfDataFilePos;
  27. m_pointerFilePositions.emplaceBack(m_alloc, pinfo);
  28. // Write the array
  29. ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::BEGINNING));
  30. ANKI_CHECK(m_file->write(arr, size));
  31. }
  32. check();
  33. return Error::NONE;
  34. }
  35. } // end namespace anki