Packet.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* ----------------------------------------------------------------------------
  2. * This file was automatically generated by SWIG (http://www.swig.org).
  3. * Version 2.0.1
  4. *
  5. * Do not make changes to this file unless you know what you are doing--modify
  6. * the SWIG interface file instead.
  7. * ----------------------------------------------------------------------------- */
  8. namespace RakNet {
  9. using System;
  10. using System.Runtime.InteropServices;
  11. public class Packet : IDisposable {
  12. private HandleRef swigCPtr;
  13. protected bool swigCMemOwn;
  14. internal Packet(IntPtr cPtr, bool cMemoryOwn)
  15. {
  16. swigCMemOwn = cMemoryOwn;
  17. swigCPtr = new HandleRef(this, cPtr);
  18. }
  19. internal static HandleRef getCPtr(Packet obj)
  20. {
  21. if (obj != null)
  22. {
  23. if (obj.dataIsCached)
  24. {
  25. obj.SetPacketData(obj.data, obj.data.Length); //If an individual index was modified we need to copy the data before passing to C++
  26. }
  27. obj.dataIsCached=false;
  28. }
  29. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  30. }
  31. ~Packet() {
  32. Dispose();
  33. }
  34. public virtual void Dispose() {
  35. lock(this) {
  36. if (swigCPtr.Handle != IntPtr.Zero) {
  37. if (swigCMemOwn) {
  38. swigCMemOwn = false;
  39. RakNetPINVOKE.delete_Packet(swigCPtr);
  40. }
  41. swigCPtr = new HandleRef(null, IntPtr.Zero);
  42. }
  43. GC.SuppressFinalize(this);
  44. }
  45. }
  46. private bool dataIsCached = false;
  47. private byte[] dataCache;
  48. public SystemAddress systemAddress {
  49. set {
  50. RakNetPINVOKE.Packet_systemAddress_set(swigCPtr, SystemAddress.getCPtr(value));
  51. }
  52. get {
  53. IntPtr cPtr = RakNetPINVOKE.Packet_systemAddress_get(swigCPtr);
  54. SystemAddress ret = (cPtr == IntPtr.Zero) ? null : new SystemAddress(cPtr, false);
  55. return ret;
  56. }
  57. }
  58. public RakNetGUID guid {
  59. set {
  60. RakNetPINVOKE.Packet_guid_set(swigCPtr, RakNetGUID.getCPtr(value));
  61. }
  62. get {
  63. IntPtr cPtr = RakNetPINVOKE.Packet_guid_get(swigCPtr);
  64. RakNetGUID ret = (cPtr == IntPtr.Zero) ? null : new RakNetGUID(cPtr, false);
  65. return ret;
  66. }
  67. }
  68. public uint length {
  69. set {
  70. RakNetPINVOKE.Packet_length_set(swigCPtr, value);
  71. }
  72. get {
  73. uint ret = RakNetPINVOKE.Packet_length_get(swigCPtr);
  74. return ret;
  75. }
  76. }
  77. public uint bitSize {
  78. set {
  79. RakNetPINVOKE.Packet_bitSize_set(swigCPtr, value);
  80. }
  81. get {
  82. uint ret = RakNetPINVOKE.Packet_bitSize_get(swigCPtr);
  83. return ret;
  84. }
  85. }
  86. public byte[] data {
  87. set
  88. {
  89. dataCache=value;
  90. dataIsCached = true;
  91. SetPacketData (value, value.Length);
  92. }
  93. get
  94. {
  95. byte[] returnBytes;
  96. if (!dataIsCached)
  97. {
  98. IntPtr cPtr = RakNetPINVOKE.Packet_data_get (swigCPtr);
  99. int len = (int)((Packet)swigCPtr.Wrapper).length;
  100. if (len<=0)
  101. {
  102. return null;
  103. }
  104. returnBytes = new byte[len];
  105. Marshal.Copy(cPtr, returnBytes, 0, len);
  106. dataCache = returnBytes;
  107. dataIsCached = true;
  108. }
  109. else
  110. {
  111. returnBytes = dataCache;
  112. }
  113. return returnBytes;
  114. }
  115. }
  116. public bool deleteData {
  117. set {
  118. RakNetPINVOKE.Packet_deleteData_set(swigCPtr, value);
  119. }
  120. get {
  121. bool ret = RakNetPINVOKE.Packet_deleteData_get(swigCPtr);
  122. return ret;
  123. }
  124. }
  125. public bool wasGeneratedLocally {
  126. set {
  127. RakNetPINVOKE.Packet_wasGeneratedLocally_set(swigCPtr, value);
  128. }
  129. get {
  130. bool ret = RakNetPINVOKE.Packet_wasGeneratedLocally_get(swigCPtr);
  131. return ret;
  132. }
  133. }
  134. public Packet() : this(RakNetPINVOKE.new_Packet(), true) {
  135. }
  136. public void SetPacketData(byte[] inByteArray, int numBytes) {
  137. RakNetPINVOKE.Packet_SetPacketData(swigCPtr, inByteArray, numBytes);
  138. }
  139. }
  140. }
粤ICP备19079148号