public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ByteType actualValue   = (ByteType)value;
            ByteType comparedValue = (ByteType)parameter;

            return((actualValue & comparedValue) == comparedValue);
        }
Esempio n. 2
0
        public static long GetSize(this ByteType type, long size)
        {
            long bitDigits = 1;

            if (type == ByteType.Auto)
            {
                if (size >= Long1024 * Long1024 * Long1024)
                {
                    bitDigits = Long1024 * Long1024 * Long1024;
                }
                else if (size >= Long1024 * Long1024)
                {
                    bitDigits = Long1024 * Long1024;
                }
                else if (size >= Long1024)
                {
                    bitDigits = Long1024;
                }
                else
                {
                    bitDigits = 1;
                }
            }
            else
            {
                bitDigits = type.ToBitDigits();
            }

            var remainder = (size % bitDigits) > 0 ? 1 : 0;

            return(size / bitDigits + remainder);
        }
Esempio n. 3
0
        /// <summary>
        /// Marks a contiguous range of bytes as the given type, and marks
        /// the first byte in this range as a lead byte. The address range
        /// must be on the same segment.
        /// </summary>
        public void UpdateByteType(Address startAddress, Address endAddress, ByteType type)
        {
            if (startAddress.Segment != endAddress.Segment)
            {
                throw new ArgumentException("startAddress and endAddress must be on the same segment.");
            }

            ArraySegment <ByteAttribute> attrs = attributes.GetAttributes(
                startAddress, endAddress.Offset - startAddress.Offset);

            for (int i = 0; i < attrs.Count; i++)
            {
                if (attrs.Array[attrs.Offset + i].Type != ByteType.Unknown)
                {
                    // Undo
                    for (int j = i - 1; j >= 0; j--)
                    {
                        attrs.Array[attrs.Offset + j] = ByteAttribute.Empty;
                    }
                    throw new ArgumentException("[start, end) overlaps with analyzed bytes.");
                }

                ByteAttribute attr = new ByteAttribute {
                    Type       = type,
                    IsLeadByte = (i == 0),
                };
                attrs.Array[attrs.Offset + i] = attr;
            }

            OnBytesAnalyzed(startAddress, endAddress);
        }
Esempio n. 4
0
        public void Equals()
        {
            ByteType type = (ByteType)NHibernateUtil.Byte;

            Assert.IsTrue(type.IsEqual((byte)5, (byte)5));
            Assert.IsFalse(type.IsEqual((byte)5, (byte)6));
        }
Esempio n. 5
0
        public static double GetSizeDouble(this ByteType type, long size)
        {
            var bitDigits = 1.0d;

            if (type == ByteType.Auto)
            {
                if (size >= Long1024 * Long1024 * Long1024)
                {
                    bitDigits = Long1024 * Long1024 * Long1024;
                }
                else if (size >= Long1024 * Long1024)
                {
                    bitDigits = Long1024 * Long1024;
                }
                else if (size >= Long1024)
                {
                    bitDigits = Long1024;
                }
                else
                {
                    bitDigits = 1;
                }
            }
            else
            {
                bitDigits = type.ToBitDigits();
            }

            return(size / bitDigits);
        }
        public ByteType GetByteType(uint index)
        {
            ByteType result = ByteType.None;

            if (this.GetByte(index) == 0xffu)
            {
                result |= ByteType.Clean;
            }

            if ((index & 0xfffffffcu) == this.Config.ActivePageIndex * this.Config.WordsOnPage * sizeof(UInt32))
            {
                result |= ByteType.Start;
            }
            else
            {
                UInt32 offset = index & 0xfffffffcu;
                UInt16 value  = Convert.ToUInt16((this.GetByte(offset + 1) << 8) | this.GetByte(offset));
                UInt16 key    = Convert.ToUInt16((this.GetByte(offset + 3) << 8) | this.GetByte(offset + 2));

                if (key != 0xffffu)
                {
                    if (index - offset >= 2)
                    {
                        result |= ByteType.Key;
                    }
                    else
                    {
                        result |= ByteType.Value;
                    }
                }
            }

            return(result);
        }
Esempio n. 7
0
 public MapInfo(XmlElement iXml)
 {
     this.m_Name  = iXml.GetAttribute("Name");
     this.m_Num   = ByteType.FromString(iXml.GetAttribute("Num"));
     this.m_XSize = IntegerType.FromString(iXml.GetAttribute("XSize"));
     this.m_YSize = IntegerType.FromString(iXml.GetAttribute("YSize"));
 }
Esempio n. 8
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="data">要加密的字符串</param>
        /// <param name="key">密钥</param>
        /// <returns></returns>

        public static string XxTeaEncrypt(string data, string key)
        {
            try
            {
                if (data.Length == 0)
                {
                    throw new ArgumentException("Data must be at least 1 characater in length.");
                }
                uint[] k = FormatKey(key);
                if ((data.Length % 8) != 0)
                {
                    int num6 = (8 - (data.Length % 8)) - 1;
                    for (int j = 0; j <= num6; j++)
                    {
                        data = data + "\0";
                    }
                }
                //增加的
                else
                {
                    for (int j = 0; j <= 7; j++)
                    {
                        data = data + "\0";
                    }
                }
                ArrayList list = new ArrayList(data.Length);
                list.AddRange(Encoding.Unicode.GetBytes(data));
                string str    = "";
                uint[] v      = new uint[3];
                byte[] buffer = new byte[5];
                int    num5   = list.Count - 1;
                for (int i = 0; i <= num5; i += 8)
                {
                    int index = 0;
                    do
                    {
                        buffer[index] = ByteType.FromObject(list[i + index]);
                        index++;
                    }while (index <= 3);
                    v[0] = BitConverter.ToUInt32(buffer, 0);
                    int num4 = 0;
                    do
                    {
                        buffer[num4] = ByteType.FromObject(list[(i + 4) + num4]);
                        num4++;
                    }while (num4 <= 3);
                    v[1] = BitConverter.ToUInt32(buffer, 0);

                    code(v, k);
                    str = str + ConvertUintToHexString(v[0]) + ConvertUintToHexString(v[1]);
                }
                return(str.ToString());
            }
            catch (Exception)
            {
                //return "加密失败:"+ex.Message;
                return(string.Empty);
            }
        }
Esempio n. 9
0
        public static string GetSizeStringDouble(this ByteType type, long size, int digit)
        {
            var b = type.SizeToByteName(size);

            var roundSz = Math.Round(type.GetSizeDouble(size), digit);

            return($"{roundSz} {b}");
        }
Esempio n. 10
0
        public void TestSerializeClass()
        {
            var obj = new ByteType {
                a = 7
            };
            var bytes = SerializableUtil.Serialize(obj);

            Expect.AreArraysEqual(new byte[] { 7 }, bytes);
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the scalar type for the strings, decimals, uris, etc...
        /// </summary>
        /// <param name="type"></param>
        /// <param name="scalarType"></param>
        /// <returns></returns>
        public static bool TryGetBuiltInScalarType(
            Type type,
            [NotNullWhen(true)] out ScalarType?scalarType
            )
        {
            if (type == typeof(string))
            {
                scalarType = new StringType();
            }
            else if (type == typeof(decimal))
            {
                scalarType = new DecimalType();
            }
            else if (type == typeof(int))
            {
                scalarType = new IntType();
            }
            else if (type == typeof(bool))
            {
                scalarType = new BooleanType();
            }
            else if (type == typeof(float))
            {
                scalarType = new FloatType();
            }
            else if (type == typeof(Guid))
            {
                scalarType = new UuidType();
            }
            else if (type == typeof(DateTime))
            {
                scalarType = new DateTimeType();
            }
            else if (type == typeof(byte))
            {
                scalarType = new ByteType();
            }
            else if (type == typeof(Uri))
            {
                scalarType = new UrlType();
            }
            else if (type == typeof(long))
            {
                scalarType = new LongType();
            }
            else if (type == typeof(short))
            {
                scalarType = new ShortType();
            }
            else
            {
                scalarType = null;
            }

            return(scalarType is object);
        }
Esempio n. 12
0
 public void AddBytes(int bytes, ByteType typ)
 {
     if (typ != ByteType.Sent)
     {
         rc.AddBytes((uint)bytes);
         NetworkReceived += (ulong)bytes;
         return;
     }
     sc.AddBytes((uint)bytes);
     NetworkSent += (ulong)bytes;
 }
Esempio n. 13
0
        private void SendCmd(byte[] buf, ByteType byteType)
        {
            NetDataBuf netData = null;

            if (byteType == ByteType.Single)
            {
                netData = new NetDataBuf(_socket, buf, byteType);
            }
            //else
            //    netData = new NetDataBuf(_socket_Chinese, buf, byteType);

            NetDataCenter.Instance.AddQueueSend(netData);
        }
Esempio n. 14
0
 private void SendCmd(string cmd, ByteType byteType)
 {
     AddCmdLen(ref cmd);
     byte[] byteBuf = new byte[2048];
     if (byteType == ByteType.Single)
     {
         byteBuf = Encoding.Default.GetBytes(cmd);
     }
     else
     {
         byteBuf = Encoding.Unicode.GetBytes(cmd);
     }
     SendCmd(byteBuf, byteType);
 }
Esempio n. 15
0
        public static long ToBitDigits(this ByteType type)
        {
            switch (type)
            {
            case ByteType.B: return(1);

            case ByteType.Kb: return(Long1024);

            case ByteType.Mb: return(Long1024 * Long1024);

            case ByteType.Gb: return(Long1024 * Long1024 * Long1024);

            default: return(1);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Returns true if all bytes within the given address range are of
        /// the given type. The address range must be on the same segment.
        /// </summary>
        public bool CheckByteType(Address startAddress, Address endAddress, ByteType type)
        {
            if (startAddress.Segment != endAddress.Segment)
            {
                throw new ArgumentException("startAddress and endAddress must be on the same segment.");
            }

            for (Address p = startAddress; p != endAddress; p = p + 1)
            {
                if (this[p].Type != type)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 17
0
        //public void AddData(string text, ByteType byteType)
        //{
        //    byte[] buf = null;

        //    if (byteType == ByteType.Single)
        //        buf = Encoding.Default.GetBytes(text);
        //    else if (byteType == ByteType.Double)
        //        buf = Encoding.Unicode.GetBytes(text);
        //    sb.Append(text);

        //    CheckReBufferSize(buf.Length);
        //    buf.CopyTo(byteBuf, DataLen);
        //    DataLen += buf.Length;
        //}
        public void AddData(byte[] buf, ByteType byteType)
        {
            string text = "";

            if (byteType == ByteType.Single)
            {
                text = Encoding.Default.GetString(buf);
            }
            else if (byteType == ByteType.Double)
            {
                text = Encoding.Unicode.GetString(buf);
            }
            sb.Append(text);

            CheckReBufferSize(buf.Length);
            buf.CopyTo(byteBuf, DataLen);
            DataLen += buf.Length;
        }
Esempio n. 18
0
        public FileSize(ByteType type, long byteSize)
        {
            Type     = type;
            ByteSize = byteSize;

            //! B , KB は整数で切り上げで表示するのでそれ以外は有効桁を設定している
            const int digit = 2;

            if (type == ByteType.Auto && ByteSize > 1024 * 1024)
            {
                Digit = digit;
            }

            if (type == ByteType.Mb)
            {
                Digit = digit;
            }

            if (type == ByteType.Gb)
            {
                Digit = digit;
            }
        }
Esempio n. 19
0
        public static String Oct(Object Number)
        {
            if (Number == null)
            {
                throw new ArgumentNullException("Number");
            }
            switch (ObjectType.GetTypeCode(Number))
            {
            case TypeCode.Byte:
                return(Oct(ByteType.FromObject(Number)));

            case TypeCode.Int16:
                return(Oct(ShortType.FromObject(Number)));

            case TypeCode.Boolean:
            case TypeCode.Char:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.Int32:
                return(Oct(IntegerType.FromObject(Number)));

            case TypeCode.Int64:
                return(Oct(LongType.FromObject(Number)));

            case TypeCode.UInt32:
            case TypeCode.UInt64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                return(Oct(LongType.FromObject(Number)));

            case TypeCode.String:
                return(Oct(LongType.FromString
                               (StringType.FromObject(Number))));
            }
            throw new ArgumentException(S._("VB_InvalidNumber"), "Number");
        }
Esempio n. 20
0
        public static string SizeToByteName(this ByteType type, long size)
        {
            if (type == ByteType.Auto)
            {
                if (size >= Long1024 * Long1024 * Long1024)
                {
                    return("GB");
                }
                else if (size >= Long1024 * Long1024)
                {
                    return("MB");
                }
                else if (size >= Long1024)
                {
                    return("KB");
                }
                else
                {
                    return("B");
                }
            }

            return(type.ToString().ToUpper());
        }
        public FileSize GetFileSize(string fullpath, ByteType type = ByteType.Auto)
        {
            long sz = 1;

            try
            {
                if (Directory.Exists(fullpath))
                {
                    sz = 0;
                }
                else if (File.Exists(fullpath))
                {
                    sz = new System.IO.FileInfo(fullpath).Length;
                }

                return(new FileSize(type, sz));
            }
            catch (Exception)
            {
                // ignored
            }

            return(new FileSize(type, 0));
        }
Esempio n. 22
0
 public void FromObject_NotSupported(object value, byte expected)
 {
     Assert.Throws <InvalidCastException>(() => ByteType.FromObject(value));
 }
Esempio n. 23
0
 public void AddBytes(int bytes, ByteType typ)
 {
     if(typ != ByteType.Sent)
     {
         rc.AddBytes((uint)bytes);
         NetworkReceived += (ulong)bytes;
         return;
     }
     sc.AddBytes((uint)bytes);
     NetworkSent += (ulong)bytes;
 }
Esempio n. 24
0
        private void SendCmd(byte[] buf, ByteType byteType, Socket socket)
        {
            NetDataBuf netData = new NetDataBuf(socket, buf, byteType);

            NetDataCenter.Instance.AddQueueSend(netData);
        }
Esempio n. 25
0
 public HashKey(string Key)
 {
     this.m_Key = ByteType.FromString("&H" + Key);
 }
Esempio n. 26
0
 public void FromString_ThrowsOverflowException(string value)
 {
     Assert.Throws <OverflowException>(() => ByteType.FromString(value));
 }
Esempio n. 27
0
 public void FromString_ThrowsInvalidCastException(string value)
 {
     Assert.Throws <InvalidCastException>(() => ByteType.FromString(value));
 }
Esempio n. 28
0
 public void FromString_NotSupported(string value, byte expected)
 {
     Assert.Throws <InvalidCastException>(() => ByteType.FromString(value));
 }
Esempio n. 29
0
 public void FromString(string value, byte expected)
 {
     Assert.Equal(expected, ByteType.FromString(value));
 }
Esempio n. 30
0
 public void FromObject_ThrowsOverflowException(object value)
 {
     Assert.Throws <OverflowException>(() => ByteType.FromObject(value));
 }
Esempio n. 31
0
 public void FromObject_ThrowsInvalidCastException(object value)
 {
     Assert.Throws <InvalidCastException>(() => ByteType.FromObject(value));
 }
Esempio n. 32
0
        /// <summary>
        /// Returns true if all bytes within the given address range are of
        /// the given type. The address range must be on the same segment.
        /// </summary>
        public bool CheckByteType(Address startAddress, Address endAddress, ByteType type)
        {
            if (startAddress.Segment != endAddress.Segment)
                throw new ArgumentException("startAddress and endAddress must be on the same segment.");

            for (Address p = startAddress; p != endAddress; p = p + 1)
            {
                if (this[p].Type != type)
                    return false;
            }
            return true;
        }
Esempio n. 33
0
        /// <summary>
        /// Marks a contiguous range of bytes as the given type, and marks
        /// the first byte in this range as a lead byte. The address range
        /// must be on the same segment.
        /// </summary>
        public void UpdateByteType(Address startAddress, Address endAddress, ByteType type)
        {
            if (startAddress.Segment != endAddress.Segment)
                throw new ArgumentException("startAddress and endAddress must be on the same segment.");

            ArraySegment<ByteAttribute> attrs = attributes.GetAttributes(
                startAddress, endAddress.Offset - startAddress.Offset);

            for (int i = 0; i < attrs.Count; i++)
            {
                if (attrs.Array[attrs.Offset + i].Type != ByteType.Unknown)
                {
                    // Undo
                    for (int j = i - 1; j >= 0; j--)
                    {
                        attrs.Array[attrs.Offset + j] = ByteAttribute.Empty;
                    }
                    throw new ArgumentException("[start, end) overlaps with analyzed bytes.");
                }

                ByteAttribute attr = new ByteAttribute {
                    Type = type,
                    IsLeadByte = (i == 0),
                };
                attrs.Array[attrs.Offset + i] = attr;
            }

            OnBytesAnalyzed(startAddress, endAddress);
        }
        private void Init(int minLen, int maxLen, ByteType byteType, string lenType)
        {
            _minLen = minLen;
            _maxLen = maxLen;
            _byteType = byteType;
            if (_minLen == _maxLen)
                _buffer = new byte[_minLen];

            _lenType = DataGeneratorLenTypeFactory.Create (minLen, maxLen, lenType);
        }
 public RandomByteGenerator(int minLen, int maxLen, ByteType byteType, IDataGeneratorLenType lenType)
 {
     Init(minLen, maxLen, byteType, lenType);
 }
        private void Init(int minLen, int maxLen, ByteType byteType, IDataGeneratorLenType lenType)
        {
            _minLen = minLen;
            _maxLen = maxLen;
            _byteType = byteType;
            if (_minLen == _maxLen)
                _buffer = new byte[_minLen];

            _lenType = lenType;
        }