ConnectionResponse.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // <copyright file="ConnectionResponse.cs" company="Google Inc.">
  2. // Copyright (C) 2014 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // </copyright>
  16. namespace GooglePlayGames.BasicApi.Nearby
  17. {
  18. using GooglePlayGames.OurUtils;
  19. public struct ConnectionResponse
  20. {
  21. private static readonly byte[] EmptyPayload = new byte[0];
  22. public enum Status
  23. {
  24. Accepted,
  25. Rejected,
  26. ErrorInternal,
  27. ErrorNetworkNotConnected,
  28. ErrorEndpointNotConnected,
  29. ErrorAlreadyConnected
  30. }
  31. private readonly long mLocalClientId;
  32. private readonly string mRemoteEndpointId;
  33. private readonly Status mResponseStatus;
  34. private readonly byte[] mPayload;
  35. private ConnectionResponse(long localClientId, string remoteEndpointId, Status code,
  36. byte[] payload)
  37. {
  38. this.mLocalClientId = localClientId;
  39. this.mRemoteEndpointId = Misc.CheckNotNull(remoteEndpointId);
  40. this.mResponseStatus = code;
  41. this.mPayload = Misc.CheckNotNull(payload);
  42. }
  43. public long LocalClientId
  44. {
  45. get { return mLocalClientId; }
  46. }
  47. public string RemoteEndpointId
  48. {
  49. get { return mRemoteEndpointId; }
  50. }
  51. public Status ResponseStatus
  52. {
  53. get { return mResponseStatus; }
  54. }
  55. public byte[] Payload
  56. {
  57. get { return mPayload; }
  58. }
  59. public static ConnectionResponse Rejected(long localClientId, string remoteEndpointId)
  60. {
  61. return new ConnectionResponse(localClientId, remoteEndpointId, Status.Rejected,
  62. EmptyPayload);
  63. }
  64. public static ConnectionResponse NetworkNotConnected(long localClientId, string remoteEndpointId)
  65. {
  66. return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorNetworkNotConnected,
  67. EmptyPayload);
  68. }
  69. public static ConnectionResponse InternalError(long localClientId, string remoteEndpointId)
  70. {
  71. return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorInternal,
  72. EmptyPayload);
  73. }
  74. public static ConnectionResponse EndpointNotConnected(long localClientId, string remoteEndpointId)
  75. {
  76. return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorEndpointNotConnected,
  77. EmptyPayload);
  78. }
  79. public static ConnectionResponse Accepted(long localClientId, string remoteEndpointId,
  80. byte[] payload)
  81. {
  82. return new ConnectionResponse(localClientId, remoteEndpointId, Status.Accepted,
  83. payload);
  84. }
  85. public static ConnectionResponse AlreadyConnected(long localClientId,
  86. string remoteEndpointId)
  87. {
  88. return new ConnectionResponse(localClientId, remoteEndpointId,
  89. Status.ErrorAlreadyConnected,
  90. EmptyPayload);
  91. }
  92. }
  93. }