Example #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>
        new public static Reply Create(ByteList messageBytes)
        {
            Reply result = null;

            if (messageBytes == null || messageBytes.RemainingToRead < MinimumEncodingLength)
            {
                throw new ApplicationException("Invalid message byte array");
            }

            Int16 msgType = messageBytes.PeekInt16();

            switch (msgType)
            {
            case (Int16)MESSAGE_CLASS_IDS.AckNak:
                result = AckNak.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.ReadyReply:
                result = ReadyReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.ResourceReply:
                result = ResourceReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.ConfigurationReply:
                result = ConfigurationReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.PlayingFieldReply:
                result = PlayingFieldReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.AgentListReply:
                result = AgentListReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.StatusReply:
                result = StatusReply.Create(messageBytes);
                break;

            case (Int16)MESSAGE_CLASS_IDS.EndUpdateStream:
                result = EndUpdateStream.Create(messageBytes);
                break;

            default:
                throw new ApplicationException("Invalid Message Class Id");
            }

            return(result);
        }
        /// <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 PlayingFieldReply Create(ByteList messageBytes)
        {
            PlayingFieldReply 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 PlayingFieldReply();
                result.Decode(messageBytes);
            }

            return result;
        }
        /// <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>
        new public static PlayingFieldReply Create(ByteList messageBytes)
        {
            PlayingFieldReply 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 PlayingFieldReply();
                result.Decode(messageBytes);
            }

            return(result);
        }
        public void FieldLayoutReply_Everything()
        {
            PlayingFieldLayout pfl = new PlayingFieldLayout(100, 120);
            Assert.AreEqual(100, pfl.Width);
            Assert.AreEqual(120, pfl.Height);
            Assert.IsNotNull(pfl.SidewalkSquares);

            PlayingFieldReply r1 = new PlayingFieldReply(Reply.PossibleStatus.Success, pfl, "Test");

            Assert.AreEqual(Reply.PossibleStatus.Success, r1.Status);
            Assert.IsNotNull(r1.Layout);
            Assert.AreSame(pfl, r1.Layout);

            ByteList bytes = new ByteList();
            r1.Encode(bytes);
            Message msg = Message.Create(bytes);
            Assert.IsNotNull(msg);
            Assert.IsTrue(msg is PlayingFieldReply);
            PlayingFieldReply r2 = msg as PlayingFieldReply;
            Assert.AreEqual(Reply.PossibleStatus.Success, r2.Status);

            Assert.AreEqual(pfl.Height, r2.Layout.Height);
            Assert.AreEqual(pfl.Width, r2.Layout.Width);
        }