예제 #1
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);
        }
예제 #2
0
        public static void WriteString(
            VgcApis.Libs.Streams.BitStream bitStream,
            List <string> strTable,
            string str)
        {
            var lenInBits = VgcApis.Misc.Utils.GetLenInBitsOfInt(strTable.Count);

            var index = strTable.IndexOf(str);

            if (index == -1)
            {
                bitStream.Write(false);
                bitStream.Write(str);
            }
            else
            {
                bitStream.Write(true);
                bitStream.WriteTinyInt(index, lenInBits);
            }
        }
예제 #3
0
        public void ShortIntTest()
        {
            var rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                bs.Clear();
                const int len    = 7;
                var       source = new List <int>();
                for (int j = 0; j < 3; j++)
                {
                    var val = rand.Next(127);
                    source.Add(val);
                    bs.WriteTinyInt(val, len);
                }

                for (int j = 0; j < 3; j++)
                {
                    var read = bs.ReadTinyInt(len);
                    Assert.AreEqual(source[j], read);
                }
            }
        }