Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

  1. namespace Oculus.Platform
  2. {
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public sealed class Packet : IDisposable
  6. {
  7. private readonly ulong size;
  8. private readonly IntPtr packetHandle;
  9. public Packet(IntPtr packetHandle)
  10. {
  11. this.packetHandle = packetHandle;
  12. size = (ulong) CAPI.ovr_Packet_GetSize(packetHandle);
  13. }
  14. /**
  15. * Copies all the bytes in the payload into byte[] destination. ex:
  16. * Package package ...
  17. * byte[] destination = new byte[package.Size];
  18. * package.ReadBytes(destination);
  19. */
  20. public ulong ReadBytes(byte[] destination)
  21. {
  22. if ((ulong) destination.LongLength < size)
  23. {
  24. throw new System.ArgumentException(String.Format("Destination array was not big enough to hold {0} bytes", size));
  25. }
  26. Marshal.Copy(CAPI.ovr_Packet_GetBytes(packetHandle), destination, 0, (int) size);
  27. return size;
  28. }
  29. public UInt64 SenderID
  30. {
  31. get { return CAPI.ovr_Packet_GetSenderID(packetHandle); }
  32. }
  33. public ulong Size
  34. {
  35. get { return size; }
  36. }
  37. public SendPolicy Policy
  38. {
  39. get { return (SendPolicy)CAPI.ovr_Packet_GetSendPolicy(packetHandle); }
  40. }
  41. #region IDisposable
  42. ~Packet()
  43. {
  44. Dispose();
  45. }
  46. public void Dispose()
  47. {
  48. CAPI.ovr_Packet_Free(packetHandle);
  49. GC.SuppressFinalize(this);
  50. }
  51. #endregion
  52. }
  53. }