MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / WriteBytes

Method WriteBytes

Source/Engine/Serialization/FileWriteStream.cpp:79–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void FileWriteStream::WriteBytes(const void* data, uint32 bytes)
80{
81 const uint32 bufferBytesLeft = FILESTREAM_BUFFER_SIZE - _virtualPosInBuffer;
82 if (bytes <= bufferBytesLeft)
83 {
84 Platform::MemoryCopy(_buffer + _virtualPosInBuffer, data, bytes);
85 _virtualPosInBuffer += bytes;
86 }
87 else
88 {
89 uint32 bytesWritten;
90
91 // Flush already written bytes and write more it the buffer (reduce amount of flushes)
92 if (_virtualPosInBuffer > 0)
93 {
94 Platform::MemoryCopy(_buffer + _virtualPosInBuffer, data, bufferBytesLeft);
95 data = (byte*)data + bufferBytesLeft;
96 bytes -= bufferBytesLeft;
97 _virtualPosInBuffer = 0;
98 _hasError |= _file->Write(_buffer, FILESTREAM_BUFFER_SIZE, &bytesWritten) != 0;
99 }
100
101 // Write as much as can using whole buffer
102 while (bytes >= FILESTREAM_BUFFER_SIZE)
103 {
104 Platform::MemoryCopy(_buffer, data, FILESTREAM_BUFFER_SIZE);
105 data = (byte*)data + FILESTREAM_BUFFER_SIZE;
106 bytes -= FILESTREAM_BUFFER_SIZE;
107 _hasError |= _file->Write(_buffer, FILESTREAM_BUFFER_SIZE, &bytesWritten) != 0;
108 }
109
110 // Write the rest of the buffer but without flushing its data
111 if (bytes > 0)
112 {
113 Platform::MemoryCopy(_buffer, data, bytes);
114 _virtualPosInBuffer = bytes;
115 }
116 }
117}

Callers 2

saveStateMethod · 0.45

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected