Packet.cs
1.38 KB
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
namespace Oculus.Platform
{
using System;
using System.Runtime.InteropServices;
public sealed class Packet : IDisposable
{
private readonly ulong size;
private readonly IntPtr packetHandle;
public Packet(IntPtr packetHandle)
{
this.packetHandle = packetHandle;
size = (ulong) CAPI.ovr_Packet_GetSize(packetHandle);
}
/**
* Copies all the bytes in the payload into byte[] destination. ex:
* Package package ...
* byte[] destination = new byte[package.Size];
* package.ReadBytes(destination);
*/
public ulong ReadBytes(byte[] destination)
{
if ((ulong) destination.LongLength < size)
{
throw new System.ArgumentException(String.Format("Destination array was not big enough to hold {0} bytes", size));
}
Marshal.Copy(CAPI.ovr_Packet_GetBytes(packetHandle), destination, 0, (int) size);
return size;
}
public UInt64 SenderID
{
get { return CAPI.ovr_Packet_GetSenderID(packetHandle); }
}
public ulong Size
{
get { return size; }
}
public SendPolicy Policy
{
get { return (SendPolicy)CAPI.ovr_Packet_GetSendPolicy(packetHandle); }
}
#region IDisposable
~Packet()
{
Dispose();
}
public void Dispose()
{
CAPI.ovr_Packet_Free(packetHandle);
GC.SuppressFinalize(this);
}
#endregion
}
}