コード例 #1
0
        public void Write <T>(T val)
        {
            lock (rbsWriteLock)
            {
                switch (val)
                {
                case int number:
                    numberWriter.Write(number, BitsPerInt);
                    break;

                case bool flag:
                    rawBitStream.Write(flag);
                    break;

                case Guid uuid:
                    uuidsWriter.Write(uuid);
                    break;

                case string str:
                    var cache = Encoding.UTF8.GetBytes(str);
                    bytesWriter.Write(cache);
                    break;

                default:
                    throw new NotSupportedException(
                              $"Not supported type {typeof(T)}");
                }
            }
        }
コード例 #2
0
ファイル: Address.cs プロジェクト: jiahua90/V2RayGCon-1
        public void Write(string address)
        {
            var bitStream = GetParent();
            var ip        = ParseIpAddress(address);
            var str       = Utils.CutBytes(Encoding.UTF8.GetBytes(address));
            var ipBytes   = ip?.GetAddressBytes();

            if (ipBytes != null && ipBytes.Length < str.Length)
            {
                bitStream.Write(true);
                var isIpv6 = ip.AddressFamily == AddressFamily.InterNetworkV6;
                bitStream.Write(isIpv6);
                bytesWriter.Write(ipBytes, ipBytes.Length);
            }
            else
            {
                bitStream.Write(false);
                bytesWriter.Write(str);
            }
        }
コード例 #3
0
 public void Write(Guid uuid) =>
 bytesWriter.Write(uuid.ToByteArray(), BytesPerUuid);