Exemple #1
0
 /// <summary>
 /// The serialize event.
 /// </summary>
 /// <param name="eventData">The event data.</param>
 /// <returns> The serialized event</returns>
 public byte[] SerializeEventData(EventData eventData)
 {
     using (ReusableMemoryStream stream = new ReusableMemoryStream())
     {
         BigEndianBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream);
         stream.Position = this.headerSize;
         stream.WriteByte(eventData.Code);
         if ((eventData.Parameters == null) || (eventData.Parameters.Count == 0))
         {
             binaryWriter.WriteInt16(0);
         }
         else
         {
             binaryWriter.WriteInt16((short)eventData.Parameters.Count);
             Amf3Writer writer2 = new Amf3Writer(binaryWriter);
             foreach (KeyValuePair <byte, object> pair in eventData.Parameters)
             {
                 writer2.WriteInteger((long)((ulong)pair.Key));
                 writer2.Write(pair.Value);
             }
         }
         stream.Position = 0L;
         this.headerWriter.WriteHeader(stream, RtsMessageType.Event, false);
         return(stream.ToArray());
     }
 }
Exemple #2
0
 /// <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());
     }
 }
Exemple #3
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());
     }
 }