blob: 94c195a050f03769fab3145dcabc03c23c4f3696 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "TexturePacket.h"
TexturePacket::TexturePacket()
{
this->textureName = L"";
this->dwBytes = 0;
this->pbData = nullptr;
}
TexturePacket::~TexturePacket()
{
// can't free this - it's used elsewhere
// if(this->pbData!=nullptr)
// {
// delete [] this->pbData;
// }
}
TexturePacket::TexturePacket(const wstring &textureName, PBYTE pbData, DWORD dwBytes)
{
this->textureName = textureName;
this->pbData = pbData;
this->dwBytes = dwBytes;
}
void TexturePacket::handle(PacketListener *listener)
{
listener->handleTexture(shared_from_this());
}
void TexturePacket::read(DataInputStream *dis) //throws IOException
{
textureName = dis->readUTF();
short rawBytes = dis->readShort();
if (rawBytes <= 0)
{
dwBytes = 0;
return;
}
dwBytes = (DWORD)(unsigned short)rawBytes;
if (dwBytes > 65536)
{
dwBytes = 0;
return;
}
this->pbData= new BYTE [dwBytes];
for(DWORD i=0;i<dwBytes;i++)
{
this->pbData[i] = dis->readByte();
}
}
void TexturePacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeUTF(textureName);
dos->writeShort(static_cast<short>(dwBytes));
for(DWORD i=0;i<dwBytes;i++)
{
dos->writeByte(this->pbData[i]);
}
}
int TexturePacket::getEstimatedSize()
{
return 4096;
}
|