Ejemplo n.º 1
0
        public void Default_Header_Transcoding()
        {
            ResonanceEncodingInformation encodeInfo = new ResonanceEncodingInformation();

            encodeInfo.Completed    = true;
            encodeInfo.ErrorMessage = "Test";
            encodeInfo.HasError     = true;
            encodeInfo.IsCompressed = true;
            encodeInfo.Token        = Guid.NewGuid().ToString();
            encodeInfo.Transcoding  = "test";
            encodeInfo.RPCSignature = RPCSignature.FromString("Method:Service.MyMethod");
            encodeInfo.Type         = ResonanceTranscodingInformationType.Response;

            ResonanceDefaultHeaderTranscoder transcoder = new ResonanceDefaultHeaderTranscoder();

            using (MemoryStream mWrite = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(mWrite))
                {
                    transcoder.Encode(writer, encodeInfo);
                }

                ResonanceDecodingInformation decodeInfo = new ResonanceDecodingInformation();

                using (MemoryStream mRead = new MemoryStream(mWrite.ToArray()))
                {
                    using (BinaryReader reader = new BinaryReader(mRead))
                    {
                        transcoder.Decode(reader, decodeInfo);
                    }
                }

                Assert.AreEqual(encodeInfo.Completed, decodeInfo.Completed);
                Assert.AreEqual(encodeInfo.ErrorMessage, decodeInfo.ErrorMessage);
                Assert.AreEqual(encodeInfo.HasError, decodeInfo.HasError);
                Assert.AreEqual(encodeInfo.IsCompressed, decodeInfo.IsCompressed);
                Assert.AreEqual(encodeInfo.Token, decodeInfo.Token);
                Assert.AreEqual(encodeInfo.Transcoding, decodeInfo.Transcoding);
                Assert.AreEqual(encodeInfo.Type, decodeInfo.Type);
                Assert.AreEqual(encodeInfo.RPCSignature.ToString(), "Method:Service.MyMethod");
            }
        }
        /// <summary>
        /// Decodes the header using the specified binary reader and populates the specified decoding information.
        /// </summary>
        /// <param name="reader">The binary reader.</param>
        /// <param name="info">The decoding information.</param>
        public virtual void Decode(BinaryReader reader, ResonanceDecodingInformation info)
        {
            info.ProtocolVersion = reader.ReadByte();
            info.Transcoding     = reader.ReadShortASCII();
            info.IsCompressed    = reader.ReadBoolean();
            info.Token           = reader.ReadShortASCII();
            info.Type            = (ResonanceTranscodingInformationType)reader.ReadByte();

            String rpcSignatureString = reader.ReadShortASCII();

            if (!String.IsNullOrEmpty(rpcSignatureString))
            {
                info.RPCSignature = RPCSignature.FromString(rpcSignatureString);
            }

            byte timeout = reader.ReadByte();

            if (timeout > 0)
            {
                info.Timeout = timeout;
            }

            if (info.Type == ResonanceTranscodingInformationType.Response || info.Type == ResonanceTranscodingInformationType.MessageSyncACK)
            {
                info.Completed    = reader.ReadBoolean();
                info.HasError     = reader.ReadBoolean();
                info.ErrorMessage = reader.ReadUTF8();
            }
            else if (info.Type == ResonanceTranscodingInformationType.Disconnect)
            {
                info.ErrorMessage = reader.ReadUTF8();
            }

            info.ActualMessageStreamPosition = reader.ReadUInt32();

            if (info.ProtocolVersion >= ProtocolVersion)
            {
                //Add new fields here...
            }
        }