Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private sbyte GetTinuintSigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length)
- {
- return 0;
- }
- else return (sbyte)DataArray[StartPosition];
- }
- private byte GetTinuintUnsigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length)
- {
- return 0;
- }
- else return DataArray[StartPosition];
- }
- private short GetSmallintSigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 1)
- {
- return 0;
- }
- byte[] buf = new byte[2];
- Array.Copy(DataArray, StartPosition, buf, 0, 2);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToInt16(buf,0);
- }
- private ushort GetSmallintUnsigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 1)
- {
- return 0;
- }
- byte[] buf = new byte[2];
- Array.Copy(DataArray, StartPosition, buf, 0, 2);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToUInt16(buf, 0);
- }
- private int GetMediumintSigned (byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 2)
- {
- return 0;
- }
- byte[] buf = new byte[4];
- Array.Copy(DataArray, StartPosition, buf, 0, 3);
- if (RevBO)
- {
- Array.Copy(DataArray, StartPosition, buf, 1, 3);
- Array.Reverse(buf);
- }
- else
- {
- Array.Copy(DataArray, StartPosition, buf, 0, 3);
- }
- return BitConverter.ToInt32(buf, 0);
- }
- private uint GetMediumintUnsigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 2)
- {
- return 0;
- }
- byte[] buf = new byte[4];
- if (RevBO)
- {
- Array.Copy(DataArray, StartPosition, buf, 1, 3);
- Array.Reverse(buf);
- }
- else
- {
- Array.Copy(DataArray, StartPosition, buf, 0, 3);
- }
- return BitConverter.ToUInt32(buf, 0);
- }
- private int GetIntSigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 3)
- {
- return 0;
- }
- byte[] buf = new byte[4];
- Array.Copy(DataArray, StartPosition, buf, 0, 4);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToInt32(buf, 0);
- }
- private uint GetIntUnsigned(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 3)
- {
- return 0;
- }
- byte[] buf = new byte[4];
- Array.Copy(DataArray, StartPosition, buf, 0, 4);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToUInt32(buf, 0);
- }
- private float GetFloat(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 3)
- {
- return 0;
- }
- byte[] buf = new byte[4];
- Array.Copy(DataArray, StartPosition, buf, 0, 4);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToSingle(buf, 0);
- }
- private double GetDouble(byte[] DataArray, int StartPosition)
- {
- if (StartPosition >= DataArray.Length + 7)
- {
- return 0;
- }
- byte[] buf = new byte[8];
- Array.Copy(DataArray, StartPosition, buf, 0, 8);
- if (RevBO)
- {
- Array.Reverse(buf);
- }
- return BitConverter.ToDouble(buf, 0);
- }
- private double GetN16(byte[] DataArray, int StartPosition, int Signs)
- {
- short tmpShort = GetSmallintSigned(DataArray, StartPosition);
- return tmpShort / Math.Pow(10, Signs);
- }
- private double GetN32(byte[] DataArray, int StartPosition, int Signs)
- {
- int tmpInt = GetIntSigned(DataArray, StartPosition);
- return tmpInt / Math.Pow(10, Signs);
- }
- private string GetFixedString(byte[] DataArray, int StartPosition, int Count)
- {
- if (StartPosition >= DataArray.Length + Count - 1)
- {
- return null;
- }
- //кириллица UTF8 для строк ограниченной длины не поддерживается
- //делаем буфер
- byte[] buf = new byte[Count];
- //копируем нужное количество байт в буфер
- Array.Copy(DataArray, StartPosition, buf, 0, Count);
- return StringsEncoding.GetString(buf);
- }
- private int GetBlob(byte[] DataArray, int StartPosition, out string Result)
- {
- int i = StartPosition;
- List<byte> tmpl = new List<byte>();
- while (DataArray[i] != '\0')
- {
- tmpl.Add(DataArray[i]);
- i++;
- }
- i++;
- byte[] buf = tmpl.ToArray();
- Result = StringsEncoding.GetString(buf);
- return i;
- }
- public static float ConvertToFloat(string Value, string DecimalSeparator)
- {
- NumberFormatInfo format = new NumberFormatInfo();
- format.NumberDecimalSeparator = DecimalSeparator;
- return Convert.ToSingle(Value, format);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement