wavelength 1.0.0
Loading...
Searching...
No Matches
datablockpkt.h
Go to the documentation of this file.
1#pragma once
2
4#include "os/mem.h"
5
12extern int g_nDataBlockPktType;
13
21public:
23 static constexpr int kMaxBlockSize = 256;
24
30 DataBlockPkt() = default;
31
42 DataBlockPkt(const char *pData, short nBlock, short nSize, float fProgress)
43 : InternalPacket(kFlagOrdered | kFlagGuaranteed, kAllPeers), mData(pData), mBlock(nBlock),
44 mSize(nSize), mProgress(fProgress) {
45 }
46
54 static Message *New();
55
62 void *operator new(size_t nSize) {
63 return PoolMemAlloc(static_cast<int>(nSize), "DataBlockPkt", 0);
64 }
65
71 void operator delete(void *pBlock) {
72 PoolMemFree(pBlock);
73 }
74
80 Message *Clone() override {
81 return new DataBlockPkt(*this);
82 }
83
89 int Type() override {
91 }
92
98 const char *GetName() const override {
99 return "DataBlockPkt";
100 }
101
109 void PrintExtra(PrnStream &stream) const override;
110
118 void saveGuts(BinStream &stream) const override;
119
127 void restoreGuts(BinStream &stream) override;
128
130 short GetBlock() const {
131 return mBlock;
132 }
133
135 float GetProgress() const {
136 return mProgress;
137 }
138
140 short GetSize() const {
141 return mSize;
142 }
143
145 const char *GetBuffer() const {
146 return mBuffer;
147 }
148
149private:
150 const char *mData;
151 char mBuffer[kMaxBlockSize];
152 short mBlock;
153 short mSize;
154 float mProgress;
155};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
static Message * New()
Produce a default-constructed packet on the heap.
short GetSize() const
Definition datablockpkt.h:140
short GetBlock() const
Definition datablockpkt.h:130
DataBlockPkt()=default
Construct a packet with every member left unset.
const char * GetBuffer() const
Definition datablockpkt.h:145
Message * Clone() override
Produce a heap copy of this packet.
Definition datablockpkt.h:80
const char * GetName() const override
Report this packet's class name.
Definition datablockpkt.h:98
float GetProgress() const
Definition datablockpkt.h:135
DataBlockPkt(const char *pData, short nBlock, short nSize, float fProgress)
Construct a packet for every peer, ordered and guaranteed.
Definition datablockpkt.h:42
static constexpr int kMaxBlockSize
The most bytes one block delivers.
Definition datablockpkt.h:23
void restoreGuts(BinStream &stream) override
Read what saveGuts() wrote, the bytes into mBuffer.
void saveGuts(BinStream &stream) const override
Write the block, the size, the progress, and mSize bytes from mData.
int Type() override
Report this packet's registered identity.
Definition datablockpkt.h:89
void PrintExtra(PrnStream &stream) const override
Write the sender, the receiver, the block, the size, and the progress.
InternalPacket(unsigned char nFlags=0, int nReceiver=kUnset)
Construct a packet from an unset sender.
Definition internalpacket.h:33
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
static constexpr unsigned char kFlagGuaranteed
Bit of mFlags that NetTransport::Send() turns into its guaranteed delivery bit.
Definition packet.h:28
static constexpr unsigned char kFlagOrdered
Bit of mFlags that LaunchpadRT::Send() turns into the second delivery bit of the session library.
Definition packet.h:25
static constexpr int kAllPeers
Value of mReceiver that addresses every peer.
Definition packet.h:19
Text output stream.
Definition prnstream.h:16
int g_nDataBlockPktType
Identity that DataBlockPkt::Type() reports.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.