1
0
Fork 0

Codechange: SaveFilter::Write should have a const buffer

pull/12054/head
Rubidium 2024-02-11 08:25:06 +01:00
parent 8db08da148
commit 3b6fe07732
3 changed files with 11 additions and 11 deletions

View File

@ -138,7 +138,7 @@ struct PacketWriter : SaveFilter {
return false; return false;
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
/* We want to abort the saving when the socket is closed. */ /* We want to abort the saving when the socket is closed. */
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION); if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
@ -147,7 +147,7 @@ struct PacketWriter : SaveFilter {
std::lock_guard<std::mutex> lock(this->mutex); std::lock_guard<std::mutex> lock(this->mutex);
byte *bufe = buf + size; const byte *bufe = buf + size;
while (buf != bufe) { while (buf != bufe) {
size_t written = this->current->Send_bytes(buf, bufe); size_t written = this->current->Send_bytes(buf, bufe);
buf += written; buf += written;

View File

@ -2212,7 +2212,7 @@ struct FileWriter : SaveFilter {
this->Finish(); this->Finish();
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
/* We're in the process of shutting down, i.e. in "failure" mode. */ /* We're in the process of shutting down, i.e. in "failure" mode. */
if (this->file == nullptr) return; if (this->file == nullptr) return;
@ -2295,7 +2295,7 @@ struct LZOSaveFilter : SaveFilter {
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor"); if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
const lzo_bytep in = buf; const lzo_bytep in = buf;
/* Buffer size is from the LZO docs plus the chunk header size. */ /* Buffer size is from the LZO docs plus the chunk header size. */
@ -2350,7 +2350,7 @@ struct NoCompSaveFilter : SaveFilter {
{ {
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
this->chain->Write(buf, size); this->chain->Write(buf, size);
} }
@ -2435,10 +2435,10 @@ struct ZlibSaveFilter : SaveFilter {
* @param len Amount of bytes to write. * @param len Amount of bytes to write.
* @param mode Mode for deflate. * @param mode Mode for deflate.
*/ */
void WriteLoop(byte *p, size_t len, int mode) void WriteLoop(const byte *p, size_t len, int mode)
{ {
uint n; uint n;
this->z.next_in = p; this->z.next_in = const_cast<byte *>(p);
this->z.avail_in = (uInt)len; this->z.avail_in = (uInt)len;
do { do {
this->z.next_out = this->fwrite_buf; this->z.next_out = this->fwrite_buf;
@ -2463,7 +2463,7 @@ struct ZlibSaveFilter : SaveFilter {
} while (this->z.avail_in || !this->z.avail_out); } while (this->z.avail_in || !this->z.avail_out);
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
this->WriteLoop(buf, size, 0); this->WriteLoop(buf, size, 0);
} }
@ -2562,7 +2562,7 @@ struct LZMASaveFilter : SaveFilter {
* @param len Amount of bytes to write. * @param len Amount of bytes to write.
* @param action Action for lzma_code. * @param action Action for lzma_code.
*/ */
void WriteLoop(byte *p, size_t len, lzma_action action) void WriteLoop(const byte *p, size_t len, lzma_action action)
{ {
size_t n; size_t n;
this->lzma.next_in = p; this->lzma.next_in = p;
@ -2582,7 +2582,7 @@ struct LZMASaveFilter : SaveFilter {
} while (this->lzma.avail_in || !this->lzma.avail_out); } while (this->lzma.avail_in || !this->lzma.avail_out);
} }
void Write(byte *buf, size_t size) override void Write(const byte *buf, size_t size) override
{ {
this->WriteLoop(buf, size, LZMA_RUN); this->WriteLoop(buf, size, LZMA_RUN);
} }

View File

@ -78,7 +78,7 @@ struct SaveFilter {
* @param buf The bytes to write. * @param buf The bytes to write.
* @param len The number of bytes to write. * @param len The number of bytes to write.
*/ */
virtual void Write(byte *buf, size_t len) = 0; virtual void Write(const byte *buf, size_t len) = 0;
/** /**
* Prepare everything to finish writing the savegame. * Prepare everything to finish writing the savegame.