コード例 #1
0
        /// <summary>
        /// Factor method to create a message from a byte list
        /// </summary>
        /// <param name="messageBytes">A byte list from which the message will be decoded</param>
        /// <returns>A new message of the right specialization</returns>
        public static new ReadyReply Create(ByteList messageBytes)
        {
            ReadyReply result = null;

            if (messageBytes==null || messageBytes.RemainingToRead<MinimumEncodingLength)
                throw new ApplicationException("Invalid message byte array");
            if (messageBytes.PeekInt16() != ClassId)
                throw new ApplicationException("Invalid message class id");
            else
            {
                result = new ReadyReply();
                result.Decode(messageBytes);
            }

            return result;
        }
コード例 #2
0
        public void ReadyReply_TestEverything()
        {
            ReadyReply r1 = new ReadyReply(Reply.PossibleStatus.Failure);
            Assert.AreEqual(Reply.PossibleStatus.Failure, r1.Status);

            r1 = new ReadyReply(Reply.PossibleStatus.Success, "test note");
            Assert.AreEqual(Reply.PossibleStatus.Success, r1.Status);
            Assert.AreEqual("test note", r1.Note);

            ByteList byteList = new ByteList();
            r1.Encode(byteList);

            Message msg = Message.Create(byteList);
            Assert.IsNotNull(msg);
            Assert.IsTrue(msg is ReadyReply);
            ReadyReply r2 = msg as ReadyReply;
            Assert.AreEqual(r1.Status, r2.Status);
            Assert.AreEqual(r1.Note, r2.Note);
        }