/// <summary> /// Serializes an operation response. /// </summary> /// <param name="stream">The stream.</param> /// <param name="operationResponse"> The operation response.</param> /// <exception cref="T:System.IO.InvalidDataException"> /// A value can not be serialized. ///</exception> ///<exception cref="T:System.ArrayTypeMismatchException"> /// A collection with different types can not be serialized. ///</exception> private static void SerializeOperationResponse(Stream stream, OperationResponse operationResponse) { if (operationResponse.Parameters != null) { if (operationResponse.Parameters.Remove(0xf4)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)0xf4 }); } if (operationResponse.Parameters.Remove(0)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)0 }); } if (operationResponse.Parameters.Remove(1)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)1 }); } } IBinaryWriter writer = new BigEndianBinaryWriter(stream); bool flag = !string.IsNullOrEmpty(operationResponse.DebugMessage); bool flag2 = operationResponse.Parameters != null; int num = flag2 ? operationResponse.Parameters.Count : 0; num += flag ? 3 : 2; writer.WriteInt16((short)num); writer.WriteByte(0xf4); GpBinaryByteWriter.Write(writer, operationResponse.OperationCode); writer.WriteByte(0); GpBinaryByteWriter.Write(writer, (int)operationResponse.ReturnCode); if (flag) { writer.WriteByte(1); GpBinaryByteWriter.Write(writer, operationResponse.DebugMessage); } if (flag2) { foreach (KeyValuePair <byte, object> pair in operationResponse.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } }
/// <summary> /// Writes the header to the stream at the current position. /// </summary> /// <param name="stream"> The stream.</param> /// <param name="messageType"> The message type.</param> /// <param name="encrypted"> Indiciates whether the message body is encrypted.</param> public void WriteHeader(Stream stream, RtsMessageType messageType, bool encrypted) { BigEndianBinaryWriter.WriteByte(stream, 0xf4); byte num = (byte)messageType; if (encrypted) { num = (byte)(num | 0x80); } BigEndianBinaryWriter.WriteByte(stream, num); }
/// <summary> /// Serializes an operation request. /// </summary> /// <param name="stream">The stream.</param> /// <param name="operationRequest"> The operation request.</param> /// <exception cref="T:System.IO.InvalidDataException"> /// A value can not be serialized. ///</exception> ///<exception cref="T:System.ArrayTypeMismatchException"> /// A collection with different types can not be serialized. ///</exception> private static void SerializeOperationRequest(Stream stream, OperationRequest operationRequest) { IBinaryWriter writer = new BigEndianBinaryWriter(stream); writer.WriteByte(operationRequest.OperationCode); writer.WriteBoolean(false); if (operationRequest.Parameters != null) { writer.WriteInt16((short)operationRequest.Parameters.Count); foreach (KeyValuePair <byte, object> pair in operationRequest.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } else { writer.WriteInt16(0); } }
/// <summary> /// Serializes an <see cref="T:Photon.SocketServer.OperationResponse"/>. /// </summary> /// <param name="operationResponse">The operation response to serialize.</param> /// <returns>The serialized operation response.</returns> public byte[] SerializeOperationResponse(OperationResponse operationResponse) { using (ReusableMemoryStream stream = new ReusableMemoryStream()) { BigEndianBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream); stream.Position = this.headerSize; binaryWriter.WriteByte(operationResponse.OperationCode); binaryWriter.WriteInt16(operationResponse.ReturnCode); if (string.IsNullOrEmpty(operationResponse.DebugMessage)) { binaryWriter.WriteByte(0x2a); } else { binaryWriter.WriteByte(0x73); binaryWriter.WriteUTF(operationResponse.DebugMessage); } if ((operationResponse.Parameters == null) || (operationResponse.Parameters.Count == 0)) { binaryWriter.WriteInt16(0); } else { binaryWriter.WriteInt16((short)operationResponse.Parameters.Count); Amf3Writer writer2 = new Amf3Writer(binaryWriter); foreach (KeyValuePair <byte, object> pair in operationResponse.Parameters) { writer2.WriteInteger((long)((ulong)pair.Key)); writer2.Write(pair.Value); } } stream.Position = 0L; this.headerWriter.WriteHeader(stream, RtsMessageType.OperationResponse, false); return(stream.ToArray()); } }
/// <summary> /// serializes the event data to a stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="eventData">The event data.</param> private void SerializeEventData(ReusableMemoryStream stream, IEventData eventData) { if ((eventData.Parameters != null) && eventData.Parameters.Remove(0xf4)) { log.WarnFormat("SendEvent - removed reserved parameter {1} from event {0}", new object[] { eventData.Code, (byte)0xf4 }); } BigEndianBinaryWriter writer = new BigEndianBinaryWriter(stream); stream.Seek((long)this.headerSize, SeekOrigin.Begin); bool flag = eventData.Parameters != null; int num = flag ? (eventData.Parameters.Count + 1) : 1; writer.WriteInt16((short)num); writer.WriteByte(0xf4); GpBinaryByteWriter.Write(writer, eventData.Code); if (flag) { foreach (KeyValuePair <byte, object> pair in eventData.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } }
public static void SendMessage(Socket udp, byte id, params byte[] payload) { byte[] msg = new byte[payload.Length + 4]; uint innerLen = (uint)payload.Length; // bridge message format (all numbers big endian) // bridge command - UINT8 (0 = transmit) // --start payload-- // inner command - UINT8 // inner payload length - UINT16 // payload msg[0] = BRIDGE_CMD_TX; msg[1] = id; msg[2] = (byte)((innerLen >> 8) & 0xff); msg[3] = (byte)(innerLen & 0xff); // copy over the payload Buffer.BlockCopy(payload, 0, msg, 4, payload.Length); // send that ish out udp.SendTo(msg, ControllerEP); if (payload.Length == 8) { msg = new byte[payload.Length + 9]; BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg); // write a slot for the timestamp (zero as we don't have any timestamp) writer.WriteUInt16(0); writer.WriteInt32(0); // write message type writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED); // write the length as bullstuff writer.WriteInt16(0); // only send for all message // change the message ID, only send a subset of the stuffs writer.WriteBytes(payload); // set the stuff stuff udp.SendTo(msg, MulticastEP); } }
/// <summary> /// Serializes an <see cref="T:Photon.SocketServer.OperationRequest"/>. /// </summary> /// <param name="operationRequest">The operation request.</param> /// <returns>The serialized operation request.</returns> public byte[] SerializeOperationRequest(OperationRequest operationRequest) { using (ReusableMemoryStream stream = new ReusableMemoryStream()) { IBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream); stream.Position = this.headerSize; binaryWriter.WriteByte(operationRequest.OperationCode); binaryWriter.WriteInt16((short)operationRequest.Parameters.Count); Amf3Writer writer2 = new Amf3Writer(binaryWriter); foreach (KeyValuePair <byte, object> pair in operationRequest.Parameters) { writer2.WriteInteger((long)((ulong)pair.Key)); writer2.Write(pair.Value); } stream.Position = 0L; this.headerWriter.WriteHeader(stream, RtsMessageType.Operation, false); return(stream.ToArray()); } }
public static void SendMessage(Socket udp, byte id, params byte[] payload) { byte[] msg = new byte[payload.Length + 4]; uint innerLen = (uint)payload.Length; // bridge message format (all numbers big endian) // bridge command - UINT8 (0 = transmit) // --start payload-- // inner command - UINT8 // inner payload length - UINT16 // payload msg[0] = BRIDGE_CMD_TX; msg[1] = id; msg[2] = (byte)((innerLen >> 8) & 0xff); msg[3] = (byte)(innerLen & 0xff); // copy over the payload Buffer.BlockCopy(payload, 0, msg, 4, payload.Length); // send that ish out udp.SendTo(msg, ControllerEP); if (payload.Length == 8) { msg = new byte[payload.Length + 9]; BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg); // write a slot for the timestamp (zero as we don't have any timestamp) writer.WriteUInt16(0); writer.WriteInt32(0); // write message type writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED); // write the length as bullstuff writer.WriteInt16(0); // only send for all message // change the message ID, only send a subset of the stuffs writer.WriteBytes(payload); // set the stuff stuff udp.SendTo(msg, MulticastEP); } }