Skip to content

Commit

Permalink
DEV9: Add PayloadData classes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored and refractionpcsx2 committed Mar 27, 2022
1 parent b23873e commit 5ac9b55
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pcsx2/DEV9/PacketReader/IP/IP_Payload.h
Expand Up @@ -28,6 +28,42 @@ namespace PacketReader::IP
virtual ~IP_Payload() {}
};

class IP_PayloadData : public IP_Payload
{
public:
std::unique_ptr<u8[]> data;

private:
int length;
u8 protocol;

public:
IP_PayloadData(int len, u8 prot)
{
protocol = prot;
length = len;

if (len != 0)
data = std::make_unique<u8[]>(len);
}
virtual int GetLength()
{
return length;
}
virtual void WriteBytes(u8* buffer, int* offset)
{
if (length == 0)
return;

memcpy(&buffer[*offset], data.get(), length);
*offset += length;
}
virtual u8 GetProtocol()
{
return protocol;
}
};

//Pointer to bytes not owned by class
class IP_PayloadPtr : public IP_Payload
{
Expand Down
31 changes: 31 additions & 0 deletions pcsx2/DEV9/PacketReader/Payload.h
Expand Up @@ -25,6 +25,37 @@ namespace PacketReader
virtual ~Payload() {}
};

//Data owned by class
class PayloadData : public Payload
{
public:
std::unique_ptr<u8[]> data;

private:
int length;

public:
PayloadData(int len)
{
length = len;

if (len != 0)
data = std::make_unique<u8[]>(len);
}
virtual int GetLength()
{
return length;
}
virtual void WriteBytes(u8* buffer, int* offset)
{
if (length == 0)
return;

memcpy(&buffer[*offset], data.get(), length);
*offset += length;
}
};

//Pointer to bytes not owned by class
class PayloadPtr : public Payload
{
Expand Down

0 comments on commit 5ac9b55

Please sign in to comment.