Ejemplo n.º 1
0
        public void KeepAliveEncoded()
        {
            Random ran                = new Random();
            UInt16 kaValue            = (UInt16)ran.Next(0, 65535);
            ConnectVariableHeader cvh = new ConnectVariableHeader(null, null, true, kaValue);

            Assert.AreEqual(kaValue.MostSignificantByte(), cvh.Encode().ToArray()[8]);
            Assert.AreEqual(kaValue.LeastSignificantByte(), cvh.Encode().ToArray()[9]);
        }
Ejemplo n.º 2
0
        public void Encoded_string_supports_extended_length_string()
        {
            string extendedLengthString = new string('x', 1000);
            UInt16 expectedLength       = (UInt16)extendedLengthString.Length;

            byte[] esBytes = new EncodedString(extendedLengthString).Encode().ToArray();
            Assert.AreEqual(expectedLength.MostSignificantByte(), esBytes[0]);
            Assert.AreEqual(expectedLength.LeastSignificantByte(), esBytes[1]);
        }
Ejemplo n.º 3
0
        public void Encoded_string_accepts_specified_max_lenth_string()
        {
            //              12345678901234567890123
            string         length23Test  = "Test 1 length to be: 23";
            UInt16         MaxSpecLength = (UInt16)length23Test.Length;
            IByteEncodable es            = new EncodedString(length23Test);

            byte[] esBytes = es.Encode().ToArray();
            Assert.AreEqual(23, MaxSpecLength);
            Assert.AreEqual(MaxSpecLength.MostSignificantByte(), esBytes[0]);
            Assert.AreEqual(MaxSpecLength.LeastSignificantByte(), esBytes[1]);
        }
Ejemplo n.º 4
0
            public void Data_length_is_counted_and_encoded_correctly()
            {
                UInt16 expectedDataLength = 52;

                byte[] exampleDataArray = new byte[expectedDataLength];

                EncodedDataField encodedDataField = new EncodedDataField(exampleDataArray);

                Assert.AreEqual(expectedDataLength, encodedDataField.Length);
                Assert.AreEqual(expectedDataLength.MostSignificantByte(), encodedDataField.Encode().First());
                Assert.AreEqual(expectedDataLength.LeastSignificantByte(), encodedDataField.Encode().Skip(1).First());
            }
Ejemplo n.º 5
0
        public override IEnumerable <byte> Encode()
        {
            UTF8Encoding utf8            = new UTF8Encoding();
            List <byte>  retBytes        = new List <byte>();
            UInt16       ProtocolNameLen = (UInt16)ProtocolName.Length;

            retBytes.Add(ProtocolNameLen.MostSignificantByte());
            retBytes.Add(ProtocolNameLen.LeastSignificantByte());
            retBytes.AddRange(utf8.GetBytes(ProtocolName));
            retBytes.Add(ProtocolLevel);
            retBytes.Add(GetFlags());
            retBytes.Add(KeepAliveTime.MostSignificantByte());
            retBytes.Add(KeepAliveTime.LeastSignificantByte());

            return(retBytes);
        }
Ejemplo n.º 6
0
        public void Verify_LSB_Helper_Function()
        {
            UInt16 packetID = 0xff88;

            Assert.AreEqual(0x88, packetID.LeastSignificantByte());
        }
Ejemplo n.º 7
0
        public IEnumerable <byte> Encode()
        {
            UInt16 length = (UInt16)Data.Count();

            return(new byte[] { length.MostSignificantByte(), length.LeastSignificantByte() }.Concat(Data));
        }