コード例 #1
0
        /// <summary>
        /// Tries to parse an operation response.
        /// </summary>
        /// <param name="data"> A byte array containing the binary operation response data.</param>
        /// <param name="operationResponse">Contains the parsed operation response, if the methods returns with success;
        /// otherwise, the parameter will be uninitialized. </param>
        /// <returns>true if the operation response was parsed successfully; otherwise false.</returns>
        public bool TryParseOperationResponse(byte[] data, out OperationResponse operationResponse)
        {
            using (MemoryStream stream = new MemoryStream(data, this.headerSize, data.Length - this.headerSize))
            {
                string str;
                BigEndianBinaryReader reader = new BigEndianBinaryReader(stream);
                byte  num  = reader.ReadByte();
                short num2 = reader.ReadInt16();
                switch (((GpType)reader.ReadByte()))
                {
                case GpType.Null:
                    str = null;
                    break;

                case GpType.String:
                    if (GpBinaryByteReader.ReadString(reader, out str))
                    {
                        break;
                    }
                    operationResponse = null;
                    return(false);

                default:
                    operationResponse = null;
                    return(false);
                }
                short capacity = reader.ReadInt16();
                Dictionary <byte, object> dictionary = new Dictionary <byte, object>(capacity);
                if (capacity > 0)
                {
                    Amf3Reader reader2 = new Amf3Reader(reader);
                    for (short i = 0; i < capacity; i = (short)(i + 1))
                    {
                        object obj2;
                        object obj3;
                        if (!reader2.Read(out obj2))
                        {
                            operationResponse = null;
                            return(false);
                        }
                        byte num5 = (byte)((int)obj2);
                        if (!reader2.Read(out obj3))
                        {
                            operationResponse = null;
                            return(false);
                        }
                        dictionary[num5] = obj3;
                    }
                }
                OperationResponse response = new OperationResponse
                {
                    DebugMessage  = str,
                    ReturnCode    = num2,
                    OperationCode = num,
                    Parameters    = dictionary
                };
                operationResponse = response;
                return(true);
            }
        }
コード例 #2
0
 /// <summary>
 /// Converts a byte array to an <see cref="T:Photon.SocketServer.EventData"/> object.
 /// </summary>
 /// <param name="data"> The data.</param>
 /// <param name="eventData">The event data.</param>
 /// <returns>true if successfull.</returns>
 public bool TryParseEventData(byte[] data, out EventData eventData)
 {
     using (MemoryStream stream = new MemoryStream(data, this.headerSize, data.Length - this.headerSize))
     {
         BigEndianBinaryReader binaryReader = new BigEndianBinaryReader(stream);
         byte  num      = binaryReader.ReadByte();
         short capacity = binaryReader.ReadInt16();
         Dictionary <byte, object> dictionary = new Dictionary <byte, object>(capacity);
         if (capacity > 0)
         {
             Amf3Reader reader2 = new Amf3Reader(binaryReader);
             for (short i = 0; i < capacity; i = (short)(i + 1))
             {
                 object obj2;
                 object obj3;
                 if (!reader2.Read(out obj2))
                 {
                     eventData = null;
                     return(false);
                 }
                 byte num4 = (byte)((int)obj2);
                 if (!reader2.Read(out obj3))
                 {
                     eventData = null;
                     return(false);
                 }
                 dictionary[num4] = obj3;
             }
         }
         EventData data2 = new EventData
         {
             Code       = num,
             Parameters = dictionary
         };
         eventData = data2;
         return(true);
     }
 }
コード例 #3
0
 /// <summary>
 ///  Tries to parse an <see cref="T:Photon.SocketServer.OperationRequest"/>.
 /// </summary>
 /// <param name="data"> The data.</param>
 /// <param name="operationRequest">The operation request.</param>
 /// <returns>True if request was parsed successfully.</returns>
 public bool TryParseOperationRequest(byte[] data, out OperationRequest operationRequest)
 {
     using (MemoryStream stream = new MemoryStream(data, this.headerSize, data.Length - this.headerSize))
     {
         BigEndianBinaryReader binaryReader = new BigEndianBinaryReader(stream);
         byte             num      = binaryReader.ReadByte();
         short            capacity = binaryReader.ReadInt16();
         OperationRequest request  = new OperationRequest
         {
             OperationCode = num,
             Parameters    = new Dictionary <byte, object>(capacity)
         };
         operationRequest = request;
         if (capacity > 0)
         {
             Amf3Reader reader2 = new Amf3Reader(binaryReader);
             for (short i = 0; i < capacity; i = (short)(i + 1))
             {
                 object obj2;
                 if (!reader2.Read(out obj2))
                 {
                     operationRequest = null;
                     return(false);
                 }
                 byte num4 = (byte)((int)obj2);
                 if (!reader2.Read(out obj2))
                 {
                     operationRequest = null;
                     return(false);
                 }
                 operationRequest.Parameters[num4] = obj2;
             }
         }
         return(true);
     }
 }