Ejemplo n.º 1
0
        /// <summary>
        /// Decodes the specified data and populates the specified decoding information.
        /// </summary>
        /// <param name="data">The encoded data.</param>
        /// <param name="info">The decoding information object to populate.</param>
        public virtual void Decode(byte[] data, ResonanceDecodingInformation info)
        {
            try
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    using (BinaryReader reader = new BinaryReader(ms))
                    {
                        _headerTranscoder.Decode(reader, info);
                        OnTranscodingInformationDecoded(info);

                        if (info.Type != ResonanceTranscodingInformationType.KeepAliveRequest
                            &&
                            info.Type != ResonanceTranscodingInformationType.KeepAliveResponse
                            &&
                            info.Type != ResonanceTranscodingInformationType.Disconnect
                            &&
                            info.Type != ResonanceTranscodingInformationType.MessageSyncACK
                            &&
                            !info.HasError)
                        {
                            ms.Position = info.ActualMessageStreamPosition;

                            byte[] msgData = reader.ReadBytes((int)(ms.Length - ms.Position));

                            if (info.IsCompressed)
                            {
                                msgData = DecompressMessageData(msgData);
                            }

                            if (EncryptionConfiguration.Enabled)
                            {
                                msgData = DecryptMessageData(msgData);
                            }

                            using (MemoryStream msgMs = new MemoryStream(msgData))
                            {
                                info.Message = Decode(msgMs);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                info.DecoderException = ex;
                throw;
            }
        }