Ejemplo n.º 1
0
        public void BsNormalTest()
        {
            var bs1  = new VgcApis.Libs.Streams.BitStream();
            var uuid = Guid.NewGuid();

            bs1.Write(true);
            bs1.Write(12345);
            bs1.Write(uuid);
            bs1.WriteAddress("abc.com");
            bs1.WriteAddress("::1");
            bs1.WriteAddress("1.2.3.4");
            bs1.Write("123");
            bs1.Write("1中23文");
            var b1 = bs1.ToBytes("1a");

            bs1.Dispose();
            var bs2 = new VgcApis.Libs.Streams.BitStream(b1);
            var b2  = bs2.ToBytes("1a");

            bs2.Dispose();

            for (int i = 0; i < b1.Length; i++)
            {
                Assert.AreEqual(b2[i], b1[i]);
            }
        }
Ejemplo n.º 2
0
        public byte[] ToBytes()
        {
            byte[] result;
            using (var bs = new VgcApis.Libs.Streams.BitStream())
            {
                bs.Clear();

                var writeString = Utils.GenWriteStringHelper(bs, strTable);

                bs.Write(alias);
                writeString(description);

                bs.Write(tlsType);
                bs.Write(isSecTls);
                bs.Write(tlsServName);

                bs.Write(port);
                bs.Write(encryption);
                bs.Write(uuid);
                bs.Write(flow);
                bs.WriteAddress(address);
                writeString(streamType);
                writeString(streamParam1);
                writeString(streamParam2);
                writeString(streamParam3);

                result = bs.ToBytes(version);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public byte[] ToBytes()
        {
            byte[] result;
            using (var bs = new VgcApis.Libs.Streams.BitStream())
            {
                var writeString = Utils.GenWriteStringHelper(bs, strTable);

                bs.Clear();

                bs.Write(alias);
                writeString(description);

                bs.WriteAddress(address);
                bs.Write(port);
                bs.Write(password);
                writeString(method);
                bs.WriteTinyInt(networkType, networkTypeLenInBits);
                bs.Write(isUseOta);

                bs.Write(isUseTls);
                writeString(streamType);
                writeString(streamParam1);
                writeString(streamParam2);
                writeString(streamParam3);

                result = bs.ToBytes(version);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public void AddressTest(string str)
        {
            bs.Clear();
            bs.WriteAddress(str);
            var result = bs.ReadAddress();

            Assert.AreEqual(str, result);
        }
Ejemplo n.º 5
0
        public void Crc8ChecksumFailTest()
        {
            var bs1 = new VgcApis.Libs.Streams.BitStream();

            bs1.Write(12345);
            bs1.WriteAddress("abc.com");

            var b1 = bs1.ToBytes("2b");

            b1[0] = (byte)(b1[0] + 1);
            try
            {
                var b2 = new VgcApis.Libs.Streams.BitStream(b1);
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }