| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Runtime.InteropServices;
- namespace ENet
- {
- public sealed class Packet : IDisposable
- {
- private IntPtr packet;
- public Packet(IntPtr packet)
- {
- this.packet = packet;
- }
- public Packet(string data, PacketFlags flags = PacketFlags.None)
- {
- if (data == null)
- {
- throw new ArgumentNullException("data");
- }
- this.packet = Native.enet_packet_create(data, (uint)data.Length, flags);
- if (this.packet == IntPtr.Zero)
- {
- throw new ENetException(0, "Packet creation call failed.");
- }
- }
- ~Packet()
- {
- Dispose(false);
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (this.packet == IntPtr.Zero)
- {
- return;
- }
- Native.enet_packet_destroy(this.packet);
- this.packet = IntPtr.Zero;
- }
- public ENetPacket Struct
- {
- get
- {
- return (ENetPacket)Marshal.PtrToStructure(this.packet, typeof(ENetPacket));
- }
- set
- {
- Marshal.StructureToPtr(value, this.packet, false);
- }
- }
- public IntPtr NativePtr
- {
- get
- {
- return this.packet;
- }
- }
- }
- }
|