forked from DarkActive/PVPNetConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacket.cs
96 lines (88 loc) · 2.01 KB
/
Packet.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PVPNetConnect
{
/// <summary>
/// The packet class.
/// </summary>
public class Packet
{
/// <summary>
/// The data buffer
/// </summary>
private byte[] dataBuffer;
/// <summary>
/// The data pos
/// </summary>
private int dataPos;
/// <summary>
/// The data size
/// </summary>
private int dataSize;
/// <summary>
/// The message type
/// </summary>
private int messageType;
/// <summary>
/// Sets the size.
/// </summary>
/// <param name="size">The size.</param>
public void SetSize(int size)
{
dataSize = size;
dataBuffer = new byte[dataSize];
}
/// <summary>
/// Sets the type.
/// </summary>
/// <param name="type">The type.</param>
public void SetType(int type)
{
messageType = type;
}
/// <summary>
/// Adds the specified b.
/// </summary>
/// <param name="b">The b.</param>
public void Add(byte b)
{
dataBuffer[dataPos++] = b;
}
/// <summary>
/// Determines whether this instance is complete.
/// </summary>
/// <returns>
/// <c>true</c> if this instance is complete; otherwise, <c>false</c>.
/// </returns>
public bool IsComplete()
{
return (dataPos == dataSize);
}
/// <summary>
/// Gets the size.
/// </summary>
/// <returns></returns>
public int GetSize()
{
return dataSize;
}
/// <summary>
/// Gets the type of the message.
/// </summary>
/// <returns></returns>
public int GetMessageType()
{
return messageType;
}
/// <summary>
/// Gets the data.
/// </summary>
/// <returns></returns>
public byte[] GetData()
{
return dataBuffer;
}
}
}