OpenTTD Source  20241108-master-g80f628063a
PacketReader Struct Reference

Read some packets, and when do use that data as initial load filter. More...

Inheritance diagram for PacketReader:
LoadFilter

Public Member Functions

 PacketReader ()
 Initialise everything.
 
void AddPacket (Packet &p)
 Add a packet to this buffer. More...
 
size_t Read (uint8_t *rbuf, size_t size) override
 Read a given number of bytes from the savegame. More...
 
void Reset () override
 Reset this filter to read from the beginning of the file.
 
- Public Member Functions inherited from LoadFilter
 LoadFilter (std::shared_ptr< LoadFilter > chain)
 Initialise this filter. More...
 
virtual ~LoadFilter ()
 Make sure the writers are properly closed.
 

Static Public Member Functions

static ssize_t TransferOutMemCopy (PacketReader *destination, const char *source, size_t amount)
 Simple wrapper around fwrite to be able to pass it to Packet's TransferOut. More...
 

Data Fields

std::vector< uint8_t * > blocks
 Buffer with blocks of allocated memory.
 
uint8_t * buf
 Buffer we're going to write to/read from.
 
uint8_t * bufe
 End of the buffer we write to/read from.
 
uint8_t ** block
 The block we're reading from/writing to.
 
size_t written_bytes
 The total number of bytes we've written.
 
size_t read_bytes
 The total number of read bytes.
 
- Data Fields inherited from LoadFilter
std::shared_ptr< LoadFilterchain
 Chained to the (savegame) filters.
 

Static Public Attributes

static const size_t CHUNK = 32 * 1024
 32 KiB chunks of memory.
 

Detailed Description

Read some packets, and when do use that data as initial load filter.

Definition at line 43 of file network_client.cpp.

Member Function Documentation

◆ AddPacket()

void PacketReader::AddPacket ( Packet p)
inline

Add a packet to this buffer.

Parameters
pThe packet to add.

Definition at line 84 of file network_client.cpp.

References CHUNK, Packet::RemainingBytesToTransfer(), TransferOutMemCopy(), and Packet::TransferOutWithLimit().

◆ Read()

size_t PacketReader::Read ( uint8_t *  buf,
size_t  len 
)
inlineoverridevirtual

Read a given number of bytes from the savegame.

Parameters
bufThe bytes to read.
lenThe number of bytes to read.
Returns
The number of actually read bytes.

Implements LoadFilter.

Definition at line 99 of file network_client.cpp.

References CHUNK.

◆ TransferOutMemCopy()

static ssize_t PacketReader::TransferOutMemCopy ( PacketReader destination,
const char *  source,
size_t  amount 
)
inlinestatic

Simple wrapper around fwrite to be able to pass it to Packet's TransferOut.

Parameters
destinationThe reader to add the data to.
sourceThe buffer to read data from.
amountThe number of bytes to copy.
Returns
The number of bytes that were copied.

Definition at line 72 of file network_client.cpp.

References buf, and written_bytes.

Referenced by AddPacket().


The documentation for this struct was generated from the following file: